Operator method lookup failure

Konstantin X kxx@gmx.com
Mon Apr 12 09:40:00 GMT 2010


Hello all,

Please consider the following example : 

> cat gcc_private_inheritance.cpp :

class A {};
class B : public A {};
class C : private B {
public:
 operator A& () {return *this;}
};

void doSomething (const A&) {}

int main (int argc, char** argv){
 C instC;
 // Attempt 1. Causes compiler error, not expected
 doSomething (instC.operator A&());
 // Attempt 2. Causes compiler error, standard-conforming behaviour
 doSomething (instC);
 // Attempt 3. Fine!
 doSomething (instC.C::operator A&());
 return 0;
}

> g++ gcc_private_inheritance.cpp -Wall -save-temps :
gcc_private_inheritance.cpp: In function ‘int main(int, char**)’:
gcc_private_inheritance.cpp:1: error: ‘class A’ is inaccessible
gcc_private_inheritance.cpp:13: error: within this context
gcc_private_inheritance.cpp:15: error: ‘A’ is an inaccessible base of ‘C

I don`t see why (1) attempt to call 'C::operator A&' method should fail while
(3) attempt succeeds.

I`ve created a bug report (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43189),
but It seems that it has been lost in time :)


Thank you



More information about the Gcc-help mailing list