Suppose I have a C++ class as follows:
class Point {
// implementing some operations
}
Then:
Point p1;
Point p2 = p1;
If I want to know the address of p2, then I can use &p2. But how can I get the address that p2 stores? Because p2 is not a pointer, so I cannot just use cout << p2;
What’s wrong with the following:
As you say,
p2is not a pointer. Conceptually it is a block of data stored somewhere in memory.&p2is the address of this block. When you do:…that data is copied to the block ‘labelled’
p1.Unless you add a pointer member to the
Pointdata structure, it doesn’t store an address. As you said, it’s not a pointer.P.S. The hex stream operator might be useful too: