C++ 错误C2582:&x27;运算符=';功能在中不可用
我有课C++ 错误C2582:&x27;运算符=';功能在中不可用,c++,compiler-errors,C++,Compiler Errors,我有课 class Points { public: Points(); } 还有一个, class OtherPoints : public Points { public: OtherPoints (); Points myPoints; } 现在在OtherPoints()构造函数中,我试图创建一个Point变量 OtherPoints::OtherPoints(){ myPoints=Points(); } 然后得到错误 错误C2582:“运算符=”函数在“点
class Points
{
public:
Points();
}
还有一个,
class OtherPoints : public Points
{
public:
OtherPoints ();
Points myPoints;
}
现在在OtherPoints()
构造函数中,我试图创建一个Point
变量
OtherPoints::OtherPoints(){
myPoints=Points();
}
然后得到错误
错误C2582:“运算符=”函数在“点”中不可用
我不认为
myPoints=Points()代码>是必需的
Points myPoints; // This code has already called the constructor (Points();)
这是我编译的代码,它编译得非常好
#include<iostream>
using namespace std;
class points{
public: points(){cout<<"constructor points called"<<endl;}
virtual ~points(){cout<<"destructor points called"<<endl;}
};
class otherpoints: public points{
points x1;
public: otherpoints(){cout<<"constructor otherpoints called"<<endl;x1=points();}
~otherpoints(){cout<<"destructor otherpoints called"<<endl;}
};
int main(int argc, char *argv[])
{
otherpoints y1=otherpoints();
return 0;
}
#包括
使用名称空间std;
班级积分{
public:points(){coutDefault赋值运算符应该可用。这是完整的代码吗?顺便说一句,类定义末尾缺少;
。修复缺少的;
(有两个),可以发布真实的代码吗?a会很有帮助。仅供参考,赋值操作本身是无用的。您的myPoints
已经构建得非常好了。