"pointer" holds the address of "Int". I want to pass that address to my given classes by reference:
class N {
public:
N(int &pPointer){
std::cout << "Address: " << &(pPointer) <<"
";
}
};
class M {
public:
M(int &pPointer):n(pPointer) {
std::cout << "Address: " << &pPointer <<"
";
}
private:
N n;
};
int main () {
int Int = 5;
int *pointer = ∬
std::cout << "Address: " << pointer <<"
";
M m(*pointer);
return 0;
}
Is this a good practice (since I'm kind of using a reference to a dereferenced pointer)?
Or is it absolutely horrible?
I simply want to avoid pointers here. (Although I'm forced to use "*pointer" in the beginning. )
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…