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

标签 c++ visual-studio-2013

更新 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/

相关文章:

c++ - 二维数组想要打印一行并且只打印第二列

c++ - 如何在 Linux 上使用 Boost/Json

c++ - 如何将 `std::lower_bound` 与这个定制容器一起使用?

c++ - 从 C++ 中的方法返回对象

c# - 从 VS 2012 升级到 VS 2013 后 WebServices 不工作

c++ - Linux、C++、Lua 5.3、CMake、未定义引用

c# - 创建简单的 ViewModel 以在 MVC 5 中的一个 View 中显示两个数据表

windows-phone-8 - 启动 TaskHost.exe 失败,试图运行 Windows Phone 8 应用程序?

c++ - FXC : error X3501: 'main' : entrypoint not found

c# - 是否可以在 Visual Studio 中创建解决方案级别的配置文件?