PRB: C2250 Error Generated with Ambiguous Multiple InheritanceLast reviewed: July 25, 1997Article ID: Q104186 |
The information in this article applies to:
SYMPTOMSWith the Microsoft C/C++ compiler, the error
Error C2250: 'identifier': Ambiguous Inheritance of 'class::member'may be generated when a class inherits from two or more classes, at least two of which derive from the same virtual base class and redefine the same base class virtual member.
CAUSEThis is expected C++ compiler behavior. In the Sample Code below, the error is generated because D::f is ambiguous. That is, both class B and class C redefine their member f(), inherited from the virtual base class A, and class D inherits from B and C. As class D has only one vtable slot for the virtual function f(), and both B::f and C::f cannot be put there, the compiler generates error C2550.
RESOLUTIONThere are two ways to avoid the error:
MORE INFORMATIONAny expression that refers to a class member must make an unambiguous reference. Unfortunately, multiple inheritance introduces the possibility for names to be inherited along more than one path. The class-member names along these paths are not necessarily unique. These name conflicts are called "ambiguities." When the compiler detects an ambiguity, it generates an error message.
Sample Code
/* Compiler options needed: /c */ class A { public: int a; virtual void e(); virtual void f(); }; class B : public virtual A { public: void f(); int a; }; class C : public virtual A { public: void f(); }; class D : public B, public C { public: void d(); }; // VC++ 4.0 - 2 C2250 errors // 'D' : ambiguous inheritance of 'B::f' // 'D' : ambiguous inheritance of 'C::f' void D::d() { a++; // OK: only one function 'a' in class 'D' e(); // OK: only one function 'e' in class 'D' f(); // error C2250 or error C2385 : // two function 'f's in class 'D' } |
Additional query words: 8.00 8.00c 9.00 9.10
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |