我想基于参数which
专门化模板,但如果我删除template < bool which2 = which >
编译失败。为什么?
如何避免重复?
#include <iostream>
template < typename T, bool which >
class Node {
T key;
public:
template < bool which2 = which >
typename std::enable_if < which2 == false, bool >::type operator < ( const Node & second );
template < bool which2 = which >
typename std::enable_if < which2 == true, bool >::type operator < ( const Node & second );
Node ( ) {
(*this) < (*this);
}
};
template < class T, bool which >
template < bool which2 >
typename std::enable_if < which2 == false, bool >::type Node < T, which >::operator < ( const Node & second ) {
std::cout << "false" << std::endl;
return false;
}
template < class T, bool which >
template < bool which2 >
typename std::enable_if < which2 == true, bool >::type Node < T, which >::operator < ( const Node & second ) {
std::cout << "true" << std::endl;
return false;
}
template < typename T, bool which >
class BH {
Node < T, which > node;
};
int main ( ) {
BH < int, true > aa;
return 0;
}