-1
我尝试运行以下代码段时遇到了一些问题。我得到错误:“不能从const A转换参数到A”。智能感知告诉我A没有合适的拷贝构造函数,但是定义了一个。无法将参数从常量A转换为A
#include<iostream>
using namespace std;
class A
{
int x, *y;
public: A(int i) { x = i; y = new int[x]; }
A(A& a) { x = a.x; y = new int[x]; }
int get_x() const { return x; }
};
int f(A a) { return a.get_x(); }
int main() {
const A a(5);
cout << (a.get_x() == f(a));
system("Pause");
}
它说“no * suitable * copy constructor”是fou ND。你的不适合复制'const'对象。 – molbdnilo