#include
using namespace std;
template
class A {
public:
void taunt() { cout << \"A\"; }
};
template
-
Template specialization can't be used to reduce the number of template arguments, to do that you should use defaults for some of the arguments.
So in order to allow usage of only one argument, and make that usage hit your specialization, you need a default for the second argument, which is the same as the first argument:
#include
using namespace std;
template
class A {
public:
void taunt() { cout << "A"; }
};
template
class A {
public:
void taunt() { cout << "B"; }
};
class B {};
class C {};
int main (int argc, char * const argv[]) {
A a;
a.taunt(); // Prints "B"
return 0;
}
- 热议问题