对于以下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/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++类成为Objc类的委托
- 是否可以使一个类成为两个不同层次结构的子类?
- 是否有编译器标志可以使较新的 gcc 版本像旧版本一样构建
- C 可以使destuructor不称为班级成员和基类攻击方的灾难
- 可以使未命名的结构静态
- 是否可以使整数仅收到一个单个数字而不是两个接收输入
- C++:有哪些常规方法可以使代码更有效地用于大数字
- 是否可以使 std 容器使用默认运算符为新?
- LD_BIND_NOW可以使可执行文件运行得更慢?
- 是否可以使头文件使文本居中?- 在控制台中
- 有什么方法可以使核心忙碌等待
- 有没有一种技术可以使虚函数在所有派生类中强制重写?
- 有没有一种方法可以使全局函数/静态成员函数一次可呼出
- 是否有一种方法可以使此C 14递归模板在C 17中短
- 编写一个可以使二维数组平坦的函数
- 有哪些优化技巧可以使我的代码运行得更快
- 有没有更好的方法可以使此代码线程安全?线程局部静态似乎是一个生硬的工具
- 如果必须在同一向量上写入线程,是否可以使用线程
- 对于具有两个模板化变量的模板化类,是否可以使一个 var 引用另一个 var
- C 中的内容可以使Windows 8应用程序不在手臂上运行