FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 06-19-2012, 01:15 PM
Zbigniew Komarnicki
 
Default 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:ut();
e.D:ut();
e.C::A:ut();
e.D::A:ut();

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">http://lists.debian.org/201206191515.00919.cblasius@gmail.com
 
Old 06-19-2012, 02:55 PM
Mateusz Łukasik
 
Default why g++ this not compile

On 19/06/12 15:15, Zbigniew Komarnicki 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:ut();
e.D:ut();
e.C::A:ut();
e.D::A:ut();

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



Hello!
I compiling your code on Debian Unstable with gcc-4.7 with:
> $ cpp problem.cpp -o problem
and all working.

Best regards.


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org

Archive: 4FE092FE.70203@linuxmint.pl">http://lists.debian.org/4FE092FE.70203@linuxmint.pl
 
Old 06-19-2012, 04:40 PM
Robert Baron
 
Default 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:ut();
*e.D:ut();
//instead of these 2 lines*
*e.C::A:ut();

*e.D::A:ut();
//use the following (obvious work a round for the previous 2 line, though it should be unnecessary)// *C c=e;// *c.A:ut();*// *D d=e;// *d.A:ut();*

*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:*http://lists.debian.org/201206191515.00919.cblasius@gmail.com
 
Old 06-20-2012, 06:51 AM
Zbigniew Komarnicki
 
Default why g++ this not compile

On Tuesday 19 of June 2012 18:40:53 you wrote:
> There is a work a round (included for completeness).
>
> //instead of these 2 lines
>
> > e.C::A:ut();
> > e.D::A:ut();
>
> //use the following (obvious work a round for the previous 2 line, though
> it should be unnecessary)
> // C c=e;
> // c.A:ut();
> // D d=e;
> // d.A:ut();

Yes, you are right.
Thank you very much.

Zbigniew


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 201206200851.53949.cblasius@gmail.com">http://lists.debian.org/201206200851.53949.cblasius@gmail.com
 

Thread Tools




All times are GMT. The time now is 06:58 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org