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

Re: why g++ this not compile



There is a work a round (included for completeness). 

On Tue, Jun 19, 2012 at 9:15 AM, Zbigniew Komarnicki <cblasius@gmail.com> wrote:
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();
//instead of these 2 lines 
 e.C::A::out();
 e.D::A::out();
//use the following (obvious work a round for the previous 2 line, though it should be unnecessary)
//  C c=e;
//  c.A::out(); 
//  D d=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


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: [🔎] 201206191515.00919.cblasius@gmail.com" target="_blank">http://lists.debian.org/[🔎] 201206191515.00919.cblasius@gmail.com


Reply to: