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 37 38 39 40 41 42 43 44 45
| template <typename A, typename B, typename C>
class Test
{
public:
template <typename T = A>
typename std::enable_if<!(std::is_same<T, int>::value), void>::type
fooA(const T & a)
{
std::cout << "fooA" << std::endl;
}
template <typename T = A>
typename std::enable_if<std::is_same<T, int>::value, void>::type
fooA(const T & a)
{
std::cout << "specialized fooA" << std::endl;
}
void fooB(const B & b)
{
std::cout << "fooB" << std::endl;
}
void fooC(const C & c)
{
std::cout << "fooC" << std::endl;
}
};
int main(int argc, char **argv)
{
Test<long, char, char> t1;
t1.fooA(1l); //fooA
t1.fooB('c'); //fooB
t1.fooC('c'); //fooC
Test<int, char, char> t2;
t2.fooA(1); //specialized fooA
t2.fooB('c'); // fooB
t2.fooC('c'); // fooC
Test<int, int, int> t3;
t3.fooA(1); //specialized fooA
t3.fooB(1); //fooB
t3.fooC(1); //fooC
} |
Partager