[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

why g++ this not compile



Hello

Why this below program do not compile under g++. 
What is the reason, that g++ do not compile ?

//------------------------------------------------------
// file: problem.cpp
#include<iostream>
using namespace std;

class A { public: void out() { cout << "A" << endl; } };
class B: public A { public: void out() { cout << "B" << endl; } };
class C: public A { public: void out() { cout << "C" << endl; } };
class D: public A { public: void out() { cout << "D" << endl; } };
class E: public C, public D { public: void out() { cout << "E" << endl; } };

int main()
{
E e;

  e.out();
  e.C::out();
  e.D::out();
  e.C::A::out();
  e.D::A::out();

  return 0;
}
//------------------------------------------------------

I compile it in this way:

$ g++ -Wall problem.cpp -o problem
problem.cpp: In function ‘int main()’:
problem.cpp:17: error: ‘A’ is an ambiguous base of ‘E’
problem.cpp:18: error: ‘A’ is an ambiguous base of ‘E’

I check it under Squueze:

$ g++ --version
g++ (Debian 4.4.5-8) 4.4.5
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

My colleague check it under Windows and it compile and run under MV Studio 
2010 without any problems. The result is as expected:
E
C
D
A
A

Is it a bug in g++ compiler under Debian?

Zbigniew


Reply to: