-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