gar*_*ese 4 c++ variadic-templates c++11
是否可以将构造函数与固定参数和构造函数模板混合使用?
我的代码:
#include <iostream>
class Test {
public:
Test(std::string, int, float) {
std::cout << "normal constructor!" << std::endl;
}
template<typename ... Tn>
Test(Tn ... args) {
std::cout << "template constructor!" << std::endl;
}
};
int main() {
Test t("Hello World!", 42, 0.07f);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这给了我"模板构造函数!".有没有办法,我的普通构造函数被调用?
当然,如果两个同样好的匹配,非模板是首选:
Test t(std::string("Hello"), 42, 0.07f);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
261 次 |
| 最近记录: |