Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-04-2008, 04:22 AM
=?windows-1252?Q?Sch=FCle_Daniel?=
 
Posts: n/a
navigating(resolution) inside double diamond

Hello NG,


I am curious why the resolution doesn't work in the following case.
$ g++ --version
g++ (GCC) 4.2.0


#include <iostream>
#include <cstdlib>

using namespace std;

// building double diamond
struct A { int x; };
struct L : A {};
struct R : A {};
struct C : L, R { int p; };
struct LL : C { int q; };
struct RR : C {};
struct D : LL, RR {};

void working() {
D d, * pd = &d; // d has 4 x-int's
C * pc[2]; // d consists of 2 C's
A * pa[4]; // and 4 A's

pc[0] = (LL *)pd; // LL branch to C
pc[1] = (RR *)pd; // RR branch to C
cout << pc[0] << endl << pc[1] << endl;

pa[0] = (L *)pc[0]; // L branch to A
pa[1] = (R *)pc[0]; // R branch to A
pa[2] = (L *)pc[1]; // L branch to A
pa[3] = (R *)pc[1]; // R branch to A

cout << pa[0] << endl << pa[1] << endl;
cout << pa[2] << endl << pa[3] << endl;

// assign all integers
for(int i=0; i<4; i++)
pa[i]->x = i;
}

void notWorking() {
D d;
//d.D::LL:C::L::A::x = 0; // <= this line
d.D::LL::q = 0;
//d.D::LL::C::p = 0; // and this line
}

int main() {
working();
notWorking();
return EXIT_SUCCESS;
}


g++ says:
error: ‘C’ is an ambiguous base of ‘D’
of cause it has 2 C bases, but the "path" to the p member is
no more ambiguous.

Is there something in the standard about this situation?
How do other compilers handle this code?

Regards, Daniel

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #2 (permalink)  
Old 08-04-2008, 03:20 PM
Alberto Ganesh Barbati
 
Posts: n/a
Re: navigating(resolution) inside double diamond

Schüle Daniel ha scritto:
>
> // building double diamond
> struct A { int x; };
> struct L : A {};
> struct R : A {};
> struct C : L, R { int p; };
> struct LL : C { int q; };
> struct RR : C {};
> struct D : LL, RR {};
>
> void notWorking() {
> D d;
> //d.D::LL:C::L::A::x = 0; // <= this line
> d.D::LL::q = 0;
> //d.D::LL::C::p = 0; // and this line
> }
>
> g++ says:
> error: ‘C’ is an ambiguous base of ‘D’
> of cause it has 2 C bases, but the "path" to the p member is
> no more ambiguous.


The "path" information is discarded. When you write D::LL::C::L::A the
compiler replaces all that with A. So d.D::LL::C::L::A::x is the same as
d.A::x and that is ambiguous.

> Is there something in the standard about this situation?


It's in 3.4.5 in the standard.

> How do other compilers handle this code?


They should behave the same way.

Ganesh


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #3 (permalink)  
Old 08-04-2008, 03:28 PM
Thomas Richter
 
Posts: n/a
Re: navigating(resolution) inside double diamond

Schüle Daniel schrieb:
> Hello NG,
>
>
> I am curious why the resolution doesn't work in the following case.
> $ g++ --version
> g++ (GCC) 4.2.0
>
>
> #include <iostream>
> #include <cstdlib>
>
> using namespace std;
>
> // building double diamond
> struct A { int x; };
> struct L : A {};
> struct R : A {};
> struct C : L, R { int p; };
> struct LL : C { int q; };
> struct RR : C {};
> struct D : LL, RR {};


Are you sure that this is your structure? There is *no* diamond here at
all. Each D has two C's, and four A's. Do you probably mean "virtual
base class"?

So long,
Thomas


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #4 (permalink)  
Old 08-05-2008, 06:10 AM
=?UTF-8?B?U2Now7xsZSBEYW5pZWw=?=
 
Posts: n/a
Re: navigating(resolution) inside double diamond


> The "path" information is discarded. When you write D::LL::C::L::A the
> compiler replaces all that with A. So d.D::LL::C::L::A::x is the same as
> d.A::x and that is ambiguous.


thank you for explanation

Is there rationale behind that, such as simplification of the compiler
or language?

>> Is there something in the standard about this situation?

>
> It's in 3.4.5 in the standard.
>
>> How do other compilers handle this code?

>
> They should behave the same way.


Regards, Daniel

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
  #5 (permalink)  
Old 08-05-2008, 06:12 AM
=?windows-1252?Q?Sch=FCle_Daniel?=
 
Posts: n/a
Re: navigating(resolution) inside double diamond


> Are you sure that this is your structure? There is *no* diamond here at
> all. Each D has two C's, and four A's. Do you probably mean "virtual
> base class"?


I am aware of the "virtual" inheritance, but it would reduce common data
members into one. I was trying to build something complex to see how
to reach all the contained members.

Regards, Daniel

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > C++


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 12:12 PM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Remortgages | Credit Card Consolidation | Mortgages | Gift Ideas | Debt



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114