更新 3 后我一直在使用 Visual Studio 2013,我收到错误 C2797,“成员初始化器列表内的列表初始化或非静态数据成员初始化器未实现”,请参阅 https://msdn.microsoft.com/en-us/library/dn793970.aspx .我想在下面的 C++ 代码中使用变通方法,但我无法弄清楚或找出它应该是什么。你能给我一个建议吗?
这是我认为我需要解决方法的地方
class Shape { // deals with color and style, and holds sequence of lines
protected:
Shape{initializer_list<Point> lst}; // add() the Points to this Shape
一个点是
#ifndef POINT_GUARD
#define POINT_GUARD
typedef void (*Callback)(void*,void*);
namespace Graph_lib {
struct Point {
int x,y;
Point(int xx, int yy) : x(xx), y(yy) { }
Point() :x(0), y(0) { }
Point& operator+=(Point d) { x+=d.x; y+=d.y; return *this; }
};
inline bool operator==(Point a, Point b) { return a.x==b.x && a.y==b.y; }
inline bool operator!=(Point a, Point b) { return !(a==b); }
}
#endif
非常感谢您的帮助。
最佳答案
构造函数是用圆括号而不是花括号来定义的。
Shape{initializer_list<Point> lst};
成为
Shape(initializer_list<Point> lst);
然后你可以使用大括号来创建一个对象:
Shape shape{point1, point2, point3 };
关于c++ - 对于以下 C++ 代码中的编译错误 C2797,我可以使用什么解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29568797/