why the output is different?

I write some code like this: #include <iostream> using namespace std; class Base1 { public: typedef Base1 base; void f() { cout<<"Base1::f()"<<endl; } }; class Base2 { typedef Base2 base; public: void f() { cout<<"Base2::f()"<<endl; } }; class A : public Base1 , public Base2 { public: A() { base::f(); } }; void main() { A a; } the output is : Base1::f() But if the definition of class A modified like this, class A : public Base2 , public Base1 { public: A() { base::f(); } }; the out will be: Base2::f() the output depends on the sequence of base class, that means the "typedef" in base class is unreliable. complier gives no warning. I try these code at both VS2005 and VS2008, the result are same.

AMDG Dongfei Yin wrote:
I write some code like this:
#include <iostream>
using namespace std;
class Base1 { public: typedef Base1 base; };
class Base2 { typedef Base2 base; public: };
class A : public Base1 , public Base2 { public: A() { base::f(); } };
the output depends on the sequence of base class, that means the "typedef" in base class is unreliable. complier gives no warning. I try these code at both VS2005 and VS2008, the result are same.
I don't think this should actually compile, since base is ambiguous. (gcc doesn't compile it) In Christ, Steven Watanabe
participants (2)
-
Dongfei Yin
-
Steven Watanabe