*Really dumb Question* about polymorphism

Lets say classes b and c are derived from class a.
Can you:
1. make a pointer of a type (a * pointer) and point that pointer at a b type object?
2 if you can, can you point that pointer pointing at b at an object of type c?
Thanks :)
Last edited on
You mean like this?

1
2
3
4
5
6
7
8
9
10
11
class A {};
class B: public A {};
class C: public A {};

int main()
{
    B b;
    C c;
    A* pA = &b; // Make it point at an object of type 'B'
    pA = &c; // Change it to point to an object of type 'C'
}

Sure, that's allowed.
Thanks :D
Topic archived. No new replies allowed.