Why is the call to f
not resolving to the first function overload? I get the error:
source.cpp: In function 'int main()':
source.cpp:12:31: error: 'A' is an inaccessible base of 'B'
class A {}; class B : A {};
void f(const A &) { std::cout << "const A &"; }
template <typename T> void f(T) { std::cout << "Generic"; }
int main() {
B b;
f(dynamic_cast<const A &>(b));
}
Note that if I take out the dynamic_cast
the code will work yet the second f
is called (it prints "Generic"). But what I'm trying to do is to get the first call. I figured a dynamic_cast
would work, but for some reason it causes problems. What am I doing wrong here?