home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 31,955 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to Thomas Richter   
   Re: Resolution of ambiguous members in m   
   24 Feb 12 15:49:31   
   
   From: daniel.kruegler@googlemail.com   
      
   On 2012-02-22 17:11, Thomas Richter wrote:   
   > If a class inheriting is a member of a same name from two distinct   
   > bases, as in the following example:   
   >   
   > struct A {   
   > int a;   
   >   
   > A()   
   > : a(1)   
   > { }   
   > };   
   >   
   > struct B {   
   > int a;   
   >   
   > B()   
   > : a(1)   
   > { }   
   > };   
   >   
   > struct C : public A,B {   
   >   
   > int getA()   
   > {   
   > return a;   
   > }   
   > };   
   >   
   > int main(int argc,char **argv)   
   > {   
   > struct C c;   
   >   
   > return c.getA();   
   > }   
   >   
   > the compiler clearly refuses the code on the basis that C::a could be   
   > either A::a or B::a. Somehow, I had the expectation that inserting a   
   >   
   > struct C : public A,B {   
   > using A::a; // <---   
   > int getA()   
   > {   
   > return a;   
   > }   
   > };   
   >   
   > should resolve this ambiguity, as it expresses what I would prefer to   
   > do, but apparently, this is not the case.   
      
   Adding the using-declaration should resolve the ambiguity. Which compiler did   
   you test? (I'm not aware of any recent compiler that does not handle this   
   situation properly).   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca