Ponga_Pundit
asked on
Polymorphism with double pointer
The code snippet below doesn't compile( VC++ 6 compiler). The error is: error C2664: 'myfn' : cannot convert parameter 1 from 'class D ** ' to 'class A ** '
--------------
class A {};
class D : public A {};
void myfn(A** ap) {}
void main()
{
D d;
D *pd=&d;
myfn(&pd);
}
--------------
But if I change the myfn() parameter to A**, and change the call to myfn(pd), it works. Why the polymorphism doesn't seem to work with double pointer?
--------------
class A {};
class D : public A {};
void myfn(A** ap) {}
void main()
{
D d;
D *pd=&d;
myfn(&pd);
}
--------------
But if I change the myfn() parameter to A**, and change the call to myfn(pd), it works. Why the polymorphism doesn't seem to work with double pointer?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sorry friemds, there was a little typo in my question. Please read the second last line as:
>> But if I change the myfn() parameter to A* ap, and change the call to myfn(pd), it works.
But still Radu's answer is fully acceptable.
>> But if I change the myfn() parameter to A* ap, and change the call to myfn(pd), it works.
But still Radu's answer is fully acceptable.
>>But if I change the myfn() parameter to A**, and change the call to myfn(pd), it works. Why the polymorphism doesn't >>seem to work with double pointer?
did you mean myfn() parameter to A*, myfn(pd) ?
you put one more '*' there am i right?
did you mean myfn() parameter to A*, myfn(pd) ?
you put one more '*' there am i right?
i was late abit. cheers.
(Looking up the standard for you will cost you more points)
I can't understand when this should be any problem, as you always can dereference a pointer to pointer
D** p;
myfn( *p );