Which (virtual) function from which class is called?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Sullivan

    #1

    Which (virtual) function from which class is called?

    Assume I have the following code structure:

    class A .... {
    ....
    f() { ..... }
    virtual vf() { ..... } }


    class B .... {
    ....
    f() { ..... }
    virtual vf() { ..... } }

    main () {

    A a;
    B b;

    A *pa = new B();
    B *pb = new A();

    pa->f();
    pb->f();
    pa->vf();
    pb->vf();
    .....

    }

    Which function is called in the four cases above ?

    Are all calls possible or are they (at least some of them) already rejected during compilation?

    Mark

Working...