求教模板达人,如何实例化对象下面这个类的对象。
如果我要用非类型模板参数,如何写
比如:
enum TYPE {
AT, BT,};
template <TYPE>
struct Init ;//特化两个用于初始化Ax
template <> struct<AT> Init {static const int i=1; };
template <> struct<BT> Init {static const int i=2; };
struct Ax{
template <TYPE t>
Ax(): a(Init<t>::i) {}
int a;
};
int main() {
///请问如何实例化一个 Ax变量???
[解决办法]
不能实例化, 模版构造函数的模版参数必须是自动推导出来, 没有参数的构造函数是没办法推导模版参数的.