带有新实例参数的c++ 11委托构造函数



使用Visual Studio Nov 2012 CTP c++编译器编译此语法时遇到问题…我只是想确定我没有错过什么明显的东西。

谢谢!

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

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.
}
// .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/

最新更新