看来我对指针有误解,
这是一个例子:(代码可能无法编译,在不同的 PC 上)
#include <iostream>
struct Debris{
long big_data;
//code
};
struct Explosion{
Debris *db;
//code
};
void test(){
Debris *db = new Debris();
db->big_data = 10000;
Explosion *e1 = new Explosion();
e1->db = db;
std::cout << "db addr:" << db <<"db value:"<< ++db->big_data <<<="" "explosion's="" db="" addr:"="" e1-="">db << "explosion's db value:" << e1->db->big_data << std::endl;
//why db and e1->db have different addresses?
//but the e1->db->big_data is changed by ref.
}
你能解释一下吗?提前致谢。