错误 C2582:"运算符 ="函数在 中不可用
error C2582: 'operator =' function is unavailable in
我有一个类,
class Points
{
public:
Points();
}
另一种是
class OtherPoints : public Points
{
public:
OtherPoints ();
Points myPoints;
}
现在在OtherPoints()
构造函数中,我正在尝试创建一个Point
变量,比如
OtherPoints::OtherPoints(){
myPoints=Points();
}
并得到错误,
错误C2582:"点"中的"operator="功能不可用
我认为不需要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;
}
输出是
称为的构造函数点
称为的构造函数点
构造函数称为的其他点
称为的构造函数点
称为的析构函数点
析构函数其他称为的点
称为的析构函数点
称为的析构函数点
我没有收到任何作业错误。
注意:无论何时进行继承,都要将基类析构函数设置为虚拟的
相关文章:
- 为什么比较运算符如此快速
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- 使用C++中的模板和运算符重载执行矩阵运算
- 为什么这个运算符<重载函数对 STL 算法不可见?
- 增量运算符与后缀混淆
- 一个关于在C++中重载布尔运算符的问题
- 运算符C++ "delete []"仅删除 2 个前值
- 模板类无法识别友元运算符
- 我可以使用条件运算符初始化C风格的字符串文字吗
- 关闭||运算符优化
- 通过继承类使用来自不同命名空间的运算符
- C++Cast运算符过载
- 如何使用AngelScript注册SFML Vector2运算符
- 重载元组索引运算符-C++
- 如何使用重载的相等(==)运算符向测试用例添加描述
- 错误 C2582:"运算符 ="功能不可用
- 为什么在分配给引用时出现此错误(C2582:"运算符 ="函数在"B"中不可用)?
- std::矢量<A>错误 C2582:"运算符 ="函数在 中不可用
- 错误 C2582:"运算符 ="函数在 中不可用
- 错误 C2582:"运算符 ="函数在"B"中不可用