Why is an incorrect function used instead of an implicit conversion?

This is my snippet:

class Base{}; class Derived : private Base{}; template<class T> class Wrapper { public: template<typename T2> Wrapper( T2&& ) { } }; // Function declarations void func( Base& param ); void func( Wrapper<Derived> ); void funcUnambiguous( Wrapper<Derived> ); // Here is the Call: Derived d = Derived(); func( d ); // <- Error 

GCC 4.9 gives me: error: 'Base' is an inaccessible base of 'Derived'

While i do

 Derived d = Derived(); funcUnambiguous( d ); 

It just works fine.

It seems that any function that requires cheap casting, even if it is distorted, hides implicit but expensive functions. Somebody knows?

+5
source share
1 answer

Updated thanks to @TC

Wrapper ctor is a custom transformation template , so the standard non-template conversion sequence > overloading with Base& takes precedence. Access checks are only performed after selecting an overload - which is too late in your case.

Complete rules are complex, more can be found here , see the section "Best viable feature."

+5
source

All Articles