language: C++ 4.7.2 (gcc-4.7.2)
date: 894 days 17 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
32
33
34
35
36
#include <iostream>
 
class Interface {};
class Impl: public Interface {};
 
class Bar
{
    struct fallback { fallback(int) {} };
    template<typename T>
    struct refwrapper { T& ref; refwrapper(T& t) : ref(t) {} };
 
    template<typename T> void foo(refwrapper<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;
    int i;
    Interface& interface = impl;
    bar.foo(impl);
    bar.foo(interface);
    bar.foo(i);
    return 0;
}
prog.cpp: In member function ‘void Bar::foo(T&) [with T = int]’:
prog.cpp:34:   instantiated from here
prog.cpp:20: error: no matching function for call to ‘Bar::foo(int&, int)’
prog.cpp:15: note: candidates are: void Bar::foo(Interface&, int)