对于以下C++代码中的编译错误 C2797,可以使用什么解决方法

What workaround can I use for compile error C2797 in the following C++ code?

本文关键字:可以使 C2797 什么 方法 解决 错误 编译 C++ 代码      更新时间:2023-10-16

我在更新 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 };