繁体   English   中英

在以下C ++代码中,我可以使用哪种解决方法来编译C2797错误?

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

我在更新3之后一直使用Visual Studio 2013,并且收到错误C2797,“未实现成员初始化程序列表内的列表初始化或未实现静态数据成员初始化程序”,请参阅https://msdn.microsoft.com/zh-cn /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 };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM