我有一个没有模板的类,但是构造函数是用模板实现的。这段代码在我的环境下可以编译通过。但是我记得我曾经看到过有人说构造函数不能是模板。请问有人能解释一下这种用法是否有效吗?
typedef double Vector;
//enum Method {A, B, C, D, E, F};
struct A {};
class Butcher
{
public:
template <class Method>
Butcher(Method);
private:
Vector a, b, c;
};
template <>
Butcher::Butcher(struct A)
: a(2), b(4), c(2)
{
// a = 0.5, 1;
// b = -1, 1, 3, 2;
// c = 0, 1;
}
感谢您,Gokul。