Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] access specifiers of base classes weirdness




On Sun, Apr 7, 2013 at 5:33 AM, scalpel4k <scalpel4k@xxxxxxxxx> wrote:

Hi guys,

 

I know this is more a question for C++ in general, but I first want your judgment.

 

The example below shows my problem. In class C, I get an ambiguity error with parameter i.

According to the c++11 standard this should not be the case in the shown example.

GCC, Clang and Codan all tell me different though.

 

Am I getting something wrong here? What do you think?

 

thanks Michi

 

>>> EXAMPLE >>>

 

class A {

protected:

int i = 0;

};

 

class B : private A {

private:

int getValue() {

return i;

}

};

 

class C : private A, public B {

private:

int getValue() {

return i;


There is an ambiguity problem here between A::i and B::A::i, which are separate fields. According to the language rules, visibility is applied after name resolution.
  

}

};

 

<<< EXAMPLE <<<

 

>>> ISO/IEC 14882:2011 >>>

 

[....] 11.2 Accessibility of base classes and base class members [class.access.base]

 

If a class is declared to be a base class (Clause 10) for another class using the public access specifier, the

public members of the base class are accessible as public members of the derived class and protected

members of the base class are accessible as protected members of the derived class. If a class is declared to

be a base class for another class using the protected access specifier, the public and protected members

of the base class are accessible as protected members of the derived class. If a class is declared to be a base

class for another class using the private access specifier, the public and protected members of the base

class are accessible as private members of the derived class. [....]

 


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/cdt-dev

-sergey 


Back to the top