作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
类的构造函数可以是模板函数。在调用此类构造函数时,编译器通常会查看提供给构造函数的参数并从中确定使用的模板参数。是否还有一些语法可以显式指定模板参数?
一个人为的例子:
struct A {
template<typename T>
A() {}
};
有没有办法实例化这个类?显式指定构造函数的模板参数的语法是什么?
如果编译器似乎没有找到正确的模板化构造函数,我的用例将是一个问题。显式指定模板参数可能会生成更有用的错误消息,甚至可以解决问题。
最佳答案
没有。 C++03 标准说:
[Note: because the explicit template argument list follows the function template name, and because conversion member function templates and constructor member function templates are called without using a function name, there is no way to provide an explicit template argument list for these function templates.] (§14.5.2/5)
关于c++ - 可以显式指定构造函数的模板参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2861839/
我是一名优秀的程序员,十分优秀!