Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error on private inheritance and function overloading

Tags:

c++

I have a problem which I narrowed down to the following code:

class A
{
};

class B : private A
{
};

void f(A*)
{
}

void f(void*)
{
}

int main()
{
  B b;
  f(&b);
}

Which gives the following error with gcc 4.7:

error: ‘A’ is an inaccessible base of ‘B’

I know that A is inaccessible but I would have liked the compiler to call f(void*). Is this behavior normal or am I doing something wrong? Or maybe it's a compiler bug?

like image 503
Philippe Avatar asked Jul 17 '26 22:07

Philippe


1 Answers

Overloading is resolved before access checking. So the compiler chooses f(A*) as the appropriate overload, then determines that &b can't be converted to A* and gives the error message.

like image 161
Pete Becker Avatar answered Jul 20 '26 15:07

Pete Becker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!