Which (virtual) function from which class is called?

M

Mark Sullivan

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top