2)
You're confusing the address of operator with the reference operator. (They're both the & symbol).
const CPerson& oPerson;
makes a const reference to another CPerson object.
Essentially
CPerson(const CPerson &oPerson);
is what's called a "copy constructor". It is the constructor that is called whenever on object is being copied to another. The 'const' is there because the object being copied shouldn't be changed, and is therefore constant.
For example:
1 2
|
CPerson bob("Bob"); // makes a person named bob
CPerson anotherbob = bob; // copies bob to anotherbob .. copy constructor called
|
1) It's not really that dangerous. std::string does something similar with the c_str() function.
Reasons it could be considered dangerous:
- the returned pointer will become invalid if the CPerson object is destroyed, or if the object moves the buffer elsewhere
- char arrays in general are dangerous because they require you be responsible to prevent buffer overflows and memory management.
0) Your = operator should return a reference, not a copy. Line 7 should be:
CPerson& operator = (const CPerson& operson);
note the additional & symbol.