I need an in implicit conversion from A* to C*;
i cannot change A’s definition or implementation.
class A
{
};
struct B: public A
{
};
struct C: public B
{
};
when i write the following:
A* p;
C* q = p;
i am getting an error C2440; cannot convert from A* to C*.
what can i do giving the fact i cannot change A. both classes are plain structs of primitive data.
The only way you can do this is to use a cast:
Because
Cis a derivative ofAand not everyAis aC, it cannot be implicitly casted (like you could implicitly cast aC*to anA*because everyCis anA(i.e.Ahas “less or equal features” thanC, but not more)).I doubt that you really must have an implicit cast between pointer types. What is it making you think you do?