JAVA之等号、传类对象参数与c++的区别
# include <iostream>using namespace std;class ClassA{private: int value;public: void seta(int value) { this->value = value; } void show() { cout<<"the value : "<<value<<endl; }};int main (){ ClassA a; a.seta(3); a.show(); cout<<"a:"<<&a<<endl; ClassA b; b.seta(4); b.show(); cout<<"b:"<<&b<<endl; b = a; a.show(); b.show(); cout<<"a:"<<&a<<", b"<<&b<<endl; b.seta(6); a.show(); b.show(); cout<<"a:"<<&a<<", b"<<&b<<endl;}
运行结果:
the value : 3
a:0x22fefc
the value : 4
b:0x22fef8
the value : 3
the value : 3
a:0x22fefc, b0x22fef8
the value : 3
the value : 6
a:0x22fefc, b0x22fef8
Process returned 0 (0x0) execution time : 0.132 s
Press any key to continue.