0

使用 Visual Studio Nov 2012 CTP C++ Compiler 编译此语法时遇到问题……只是想确保我没有遗漏一些明显的东西。

谢谢!

编辑:删除标题使其更简单。

class Location
{
public:
    Location();
};

class Shape
{
public:
    Shape();
    Shape(Location location);
};


// Doing this by pointer works ...
// Shape::Shape(Location* location){}
// Shape::Shape() : Shape(new Location()){}

Shape::Shape(Location location)
{
}

Shape::Shape()
    : Shape(Location())
    // error C2143: syntax error: missing ';' before ':'
{
    // int x = 0;
    // (void) x;  // Added these two lines in some cases to get it to compile.
    // These two lines do nothing, but get around a compiler issue.
}
4

1 回答 1

2
// .h Simplification
class Location
{
public:
  Location() {}
  Location(Location const& other) {}
};

class Shape
{
  Shape();
  Shape(Location location);
};

// How about by value or reference?
Shape::Shape(Location location)
{
}

Shape::Shape(void)
  : Shape(Location()) // error C1001: An internal error has occurred in the compiler.
{
}

int main() {}

上述代码在gcc 4.7.2中编译运行

我必须对您的代码进行一些更改才能使其编译。在简化事情时,尽量保持简化的代码编译。 http://sscce.org/

于 2013-01-16T22:14:46.867 回答