Hi all,
I have a question about references. Let's assume I have an abstract class A, and several derived classes A1,A2, etc...
I want to build another class B, that can "contain" an object of type A1/A2/A3/etc.., possibly not knowing which kind of inherited class it is, exploiting polimorphism.
A possible colution could be using a reference to an obj of class A, and this is what my textbook is suggesting (for the time being; then it follows with virtual constructors, etc).
I am not really confident with references: I verified that if I declare an object
1 2 3 4 5
|
class B
{
public:
A MyA_obj;
}
|
this turns out to be an error, because A is abstract; so I write
1 2 3 4 5
|
class B
{
public:
A& MyA_obj;
}
|
and the code runs. I just do not know what is happening when I create a "reference member" (are they called so?) in my class. Is MyA_obj a pointer to an object of class A or actually an object of class A itself?
More generally, could you please provide me with some infos about this usage of the reference operator? I only know its application in connection with pointers.
Many Thanks