[英]Syntax error 'constant error
I wrote a class which has a constructor that takes 2 parameters, but when I try to use an object of the class with those parameters I get that syntax error, I have tried everything I know to solve this but I couldn't. 我编写了一个类,该类的构造函数带有2个参数,但是当我尝试使用带有这些参数的类的对象时,出现语法错误,我已经尝试了所有已知的方法来解决此问题,但是我做不到。 the code:
编码:
class Vector2D{
public:
Vector2D(int xx, int yy) {}
Vector2D d(0, 0);
};
the error: 错误:
Error C2059 syntax error: 'constant' Project1
错误C2059语法错误:“常量” Project1
If I understand what you are shooting for, the way you'd write the class is as follows 如果我了解您要拍摄的内容,则编写课程的方式如下
class Vector2D
{
public:
Vector2D() = default;
Vector2D(int xx, int yy) : m_xx(xx), m_yy(yy) {}
private:
int m_xx = 0;
int m_yy = 0;
};
Your current issue is this line 您当前的问题是这条线
Vector2D d(0, 0);
It looks like you are trying to declare a member variable d
which is an instance of the class you are trying to define. 似乎您正在尝试声明一个成员变量
d
,它是您要定义的类的实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.