language: C++ 4.7.2 (gcc-4.7.2)
date: 898 days 11 hours ago
link:
visibility: private
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
 
class Interface {};
class Impl: public Interface {};
 
class Bar
{
    struct fallback { fallback(int) {} };
    template<typename T> void foo(T& t, fallback) {
        std::cout << "generic\n";
    }
    void foo(Interface& t, int) {
        std::cout << "overload\n";
    }
public:
    template<typename T> void foo(T& t) {
        foo(t, 0);
    }
};
template<> void Bar::foo<Interface>(Interface& t) {
    std::cout << "specialization\n";
}
 
int main() {
    Bar bar;
    Impl impl;
    Interface& interface = impl;
    bar.foo(impl);
    bar.foo(interface);
    return 0;
}
prog.cpp: In member function ‘void Bar::foo(T&) [with T = Impl]’:
prog.cpp:28:   instantiated from here
prog.cpp:17: error: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second:
prog.cpp:12: note: candidate 1: void Bar::foo(Interface&, int)
prog.cpp:9: note: candidate 2: void Bar::foo(T&, Bar::fallback) [with T = Impl]