“pointer”保存“Int”的地址。我想通过引用将该地址传递给给定的类:
class N {
public:
N(int &pPointer){
std::cout << "Address: " << &(pPointer) <<" \n";
}
};
class M {
public:
M(int &pPointer):n(pPointer) {
std::cout << "Address: " << &pPointer <<" \n";
}
private:
N n;
};
int main () {
int Int = 5;
int *pointer = ∬
std::cout << "Address: " << pointer <<" \n";
M m(*pointer);
return 0;
}
这是一个好习惯吗(因为我有点使用对取消引用指针的引用)?还是绝对可怕?我只是想在这里避免指针。(虽然我一开始就被迫使用“*pointer”。)