Virtual Inheritance

N

news-east

It's probably a silly question, but if there exists a base class A, and from
it derives classes B and C, and a further class D multiply-inherits from B
and C. Let's say B derives virtually from A, and C derives non-virtually.

What should the compiler behaviour be on instantiation of an object of type
D* ?
 
V

Victor Bazarov

news-east said:
It's probably a silly question, but if there exists a base class A, and
from it derives classes B and C, and a further class D multiply-inherits
from B and C. Let's say B derives virtually from A, and C derives
non-virtually.

What should the compiler behaviour be on instantiation of an object of
type D* ?

An object of type D* is a pointer. Instantiating it does not depend on the
base classes of D (and their base classes, and so on).

In case you made a typo and didn't intend to write D*, then there should be
two objects of class A in a D. One that comes from B and the other from C.
The Standard specifies so in 10.1/4.

V
 

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,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top