1
我想知道我能夠訪問通過引用或值傳遞的對象的私有數據嗎?此代碼有效。爲什麼?我需要一些解釋。如何訪問通過引用operator = function傳遞的對象的私有數據?
class test_t {
int data;
public:
test_t(int val = 1): data(val){}
test_t& operator=(const test_t &);
};
test_t& test_t::operator=(const test_t & o){
this->data = o.data;
return *this;
}
這只是一個規則 – kiviak
@kiviak謝謝船長明顯。 – emlai
請參閱http://stackoverflow.com/questions/6921185/why-do-objects-of-the-same-class-have-access-to-each-others-private-data –