TITLE: virtual bases with no data (Newsgroups: comp.std.c++, 9 Dec 98) CLAMAGE: >> A defensible design rule is that a virtual base class should have >> no data at all, and thus no declared constructors. The default >> constructor is then implicit and public. RUPP: Stefan Rupp >But if a base class does not have any data members, why should I make >it virtual? Does that make any sense? CLAMAGE: Steve Clamage Under this view, the base class defines only an interface. If the base class is not virtual, calls to the member functions under multiple inheritance may be ambiguous: class Base { ... virtual int f(); ... }; class A : public Base { ... }; class B : public Base { ... }; class C : public A, public B { ... }; int main() { C c; c.f(); // ambiguous } Change A and B to inherit Base virtually and the call is not ambiguous. Another reason for virtual base classes not to have data is the problem of writing assignment operators. The compiler-generated assignment operator is not guaranteed by the standard to do the right thing (because in general it is too difficult to determine what the right thing is). Tom Cargill in "C++ Programming Style" (Addison-Wesley, 1992) devotes much of chapter 9 to a discussion of assignment operators in the presence of virtual base classes. If a virtual base class has no data, this problem also goes away.