I know this is already a pointer, but I want to understand what this is exactly. Is it an address or is it a * type pointer?
If I were to store this into a variable how would I have to define that variable?
Lets take this as an example
class Adult
{
private:
Child child;
public:
Adult(){
child = new Child(this);
//to have something to hold onto and get back to the upper level of the hierarchy.
}
};
class Child
{
private:
Adult* my_adult;
public:
Child();
Child(Adult &hand){
my_adult = hand;
}
}
Okay, so where I run into the trouble is with the line of code that goes my_adult = hand;
It outputs this when I try to build the project, I will be horribly shocked if there are more behind this one.
sys/chin.cpp:19:14: error: cannot convert ‘Adult’ to ‘Adult*’ in assignment
So how does this work when being dealt with as a data type opposed to accessing members?
my_adultis a pointer,handis not, pure and simple.You either need:
or
Your first example is also illegal:
shouldn’t compile, since child is an object, not a pointer.
would be the correct version.