Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #3515

Re: // how can I access A::a?

Path csiph.com!x330-a1.tempe.blueboxinc.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date Tue, 12 Apr 2011 14:13:39 -0500
From Pete Becker <pete@versatilecoding.com>
Organization Roundhouse Consulting, Ltd.
Newsgroups comp.lang.c++
Date Tue, 12 Apr 2011 15:13:39 -0400
Message-ID <2011041215133973606-pete@versatilecodingcom> (permalink)
References <bee3f0ea-42ae-4ae4-a254-d5bc9e004f93@k5g2000yqj.googlegroups.com> <2011041214200693759-pete@versatilecodingcom> <io27j5$3v1$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1; format=flowed
Content-Transfer-Encoding 8bit
Subject Re: // how can I access A::a?
User-Agent Unison/2.1.4
Lines 77
X-Usenet-Provider http://www.giganews.com
X-Trace sv3-G7cLfzxGarMvcoUDNtwzM/CDfEY1M/jihgXZJtDGHjyMWPpqqktglS9a372sWXHb+72f8iryaXlwz/V!l94QIrUKZ1OVQg/wO3WSGQDVx61F8x5YAVMYWqMU1PwbGSDLkOVJ7zcqJT01q7WIgfYu/C9E
X-Complaints-To abuse@giganews.com
X-DMCA-Notifications http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info Otherwise we will be unable to process your complaint properly
X-Postfilter 1.3.40
X-Original-Bytes 3225
Xref x330-a1.tempe.blueboxinc.net comp.lang.c++:3515

Show key headers only | View raw


On 2011-04-12 15:01:57 -0400, Victor Bazarov said:

> On 4/12/2011 2:20 PM, Pete Becker wrote:
>> On 2011-04-12 13:34:19 -0400, Victor Bazarov said:
>> 
>>> On 4/12/2011 7:38 AM, Pete Becker wrote:
>>>> On 2011-04-11 18:52:40 -0400, dick said:
>>>> 
>>>>> /* multi_level_inheritance.cpp */
>>>>> struct A
>>>>> {
>>>>> int a;
>>>>> };
>>>>> 
>>>>> struct B1 : public A
>>>>> {
>>>>> int a;
>>>>> };
>>>>> 
>>>>> struct B2 : public A
>>>>> {
>>>>> int a;
>>>>> };
>>>>> 
>>>>> struct C : public B1, public B2
>>>>> {
>>>>> int a;
>>>>> };
>>>>> 
>>>>> int main()
>>>>> {
>>>>> C ccc;
>>>>> 
>>>>> ccc.a=123;
>>>>> 
>>>>> ccc.B1::a=456;
>>>>> 
>>>>> /* 0030 */ ccc.B1::A::a=789;
>>>>> 
>>>>> }
>>>>> 
>>>>> // c++ multi_level_inheritance.cpp
>>>>> // multi_level_inheritance.cpp: In function int main():
>>>>> // multi_level_inheritance.cpp:30: error: A is an ambiguous base of C
>>>>> 
>>>>> 
>>>>> // how can I access A::a?
>>>> 
>>>> There are two A::a's, which is why the error message said that the
>>>> reference to A is ambiguous. You need to decide which one you want to
>>>> access, then name it. Hint: there's one in B1 and one in B2.
>>> 
>>> And does the fact that the OP specifically used 'B1::' before 'A::a'
>>> matter not?
>>> 
>> 
>> Sure, but you're giving away the ending. There's clearly a problem in
>> the line ccc.a = 123; so it's not at all likely that the only error
>> message came from the line marked /* 0030 */.
> 
> Actually, since 'C' has a member 'a', which hides *both* 'B1::a' and 
> 'B2::a' (which in turn hid both 'A::a' from base class 'A'), I would 
> not expect to see an error in 'ccc.a = 123;'.  Just saying...
> 
>> 
>> On the other hand, it does help to carefully read the code in question. :-(
>> 
> 

It does help to carefully read the code in question. :-(

-- 
  Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com) Author of "The 
Standard C++ Library Extensions: a Tutorial and Reference 
(www.petebecker.com/tr1book)

Back to comp.lang.c++ | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

// how can I access A::a? dick <dick_12345678@hotmail.com> - 2011-04-11 15:52 -0700
  Re: // how can I access A::a? Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-04-12 01:08 +0200
    Re: // how can I access A::a? dick <dick_12345678@hotmail.com> - 2011-04-11 16:56 -0700
      Re: // how can I access A::a? Carlo Milanesi <carlo.nospam.milanesi@libero.it> - 2011-04-12 18:46 +0200
        Re: // how can I access A::a? Miles Bader <miles@gnu.org> - 2011-04-13 15:57 +0900
  Re: // how can I access A::a? Pete Becker <pete@versatilecoding.com> - 2011-04-12 07:38 -0400
    Re: // how can I access A::a? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-12 13:34 -0400
      Re: // how can I access A::a? Pete Becker <pete@versatilecoding.com> - 2011-04-12 14:20 -0400
        Re: // how can I access A::a? Victor Bazarov <v.bazarov@comcast.invalid> - 2011-04-12 15:01 -0400
          Re: // how can I access A::a? Pete Becker <pete@versatilecoding.com> - 2011-04-12 15:13 -0400

csiph-web