给出输出结果:
A,编译错误
B,编译成功,运行错误
C,编译正常,输出10
#include <iostream> using namespace std; class A { private: int value; public: A(int a) { value =a; } A ( A other) { value =other.value; } void Print() { cout<<value<<endl; } }; int main() { A a = 10; A b = a; b.Print(); system("pause"); return 0; }
结果:编译不过
正确的代码
#include <iostream> using namespace std; class A { private: int value; public: A(int a) { value =a; } A ( const A &other) { value =other.value; } void Print() { cout<<value<<endl; } }; int main() { A a = 10; A b = a; b.Print(); system("pause"); return 0; }