D
Daniel Luis dos Santos
Hello,
I have two classes A and B. B is a subclass of A.
I then have another class C. This one has the following methods :
int doSomething(A *obj);
int doSomething(B *obj);
C also has as a member an instance of A,
private:
A *obj;
In one of C's methods I have in the previous attribute an instance of
B, with which I will call :
doSomething(obj);
Stepping through this, I noticed that the "int doSomething(A *obj)" is
called instead of the other, although the instance at runtime is of
class B. I guess that's because obj was declared as being of type A. I
was expecting that the other method would be called.
Is there some other way of doing this ?
I have two classes A and B. B is a subclass of A.
I then have another class C. This one has the following methods :
int doSomething(A *obj);
int doSomething(B *obj);
C also has as a member an instance of A,
private:
A *obj;
In one of C's methods I have in the previous attribute an instance of
B, with which I will call :
doSomething(obj);
Stepping through this, I noticed that the "int doSomething(A *obj)" is
called instead of the other, although the instance at runtime is of
class B. I guess that's because obj was declared as being of type A. I
was expecting that the other method would be called.
Is there some other way of doing this ?