问题描述
类的构造函数可以是模板函数。在调用这样的构造函数时,编译器通常查看给予构造函数的参数,并从它们确定使用的模板参数。还有一些语法明确指定模板参数?
A constructor of a class can be a template function. At the point where such a constructor is called, the compiler usually looks at the arguments given to the constructor and determines the used template parameters from them. Is there also some syntax to specify the template parameters explicitly?
一个有用的例子:
struct A {
template<typename T>
A() {}
};
有一种方法来实例化这个类吗?显式指定构造函数的模板参数的语法是什么?
Is there a way to instantiate this class? What is the syntax to explicitly specify the constructor's template parameters?
我的用例会是一个问题,编译器似乎找不到正确的模板构造函数。显式指定模板参数可能会生成更有用的错误消息,甚至解决问题。
My use case would be a problem were the compiler doesn't seem to find the correct templated constructor. Explicitly specifying the template parameters would probably generate more useful error messages or even resolve the problem.
推荐答案
否。 C ++ 03标准说:
No. The C++03 standard says:
这篇关于可以明确指定构造函数的模板参数吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!