无法让我的模板工作.非法使用显式模板参数
Cant get my template to work. Illegal use of explicit template arguments?
我试图使用模板作为变量类型通过类来创建我的不同单位。它说这是"非法使用显式模板参数"。
template <class Type>
void Build<Type>()
{
pUnit = new Type();
unitArray.push_back(pUnit);
}
我是否必须以某种方式指定类类型是单位?当我将"模板<类类型>"更改为"模板<单元类型>"时,它告诉我它是"非类型模板参数的非法类型"。我不知道我需要做什么才能使它合法化。单元类型>类类型>
"
非法使用显式模板参数"只是无效的函数模板声明语法。<Type>
在函数模板名称之后做什么?它应该是公正的
template <class Type>
void Build()
{
// ...
}
我无法判断 unitArray 是什么,所以我假设它是 Type 的向量。我也分不清 pUnit 是什么,我假设它是类型类型。
你有一个名为 Build 的函数,将其替换为 void Build(){}。
除非这个函数在类实现中,否则你需要将 pUnit 和 unitArray 声明为我上面提到的类型的参数。
template <class Type>
void Build()
{
pUnit = new Type;
unitArray.push_back(pUnit);
}
或
template <class Type>
void Build(vector<Type> unitArray, Type * pUnit)
{
pUnit = new Type;
unitArray.push_back(pUnit);
}
相关文章:
- 如何使我的 sizeof sum 结构与空参数包一起工作
- 如何定义在用作函数参数时工作的类模板的转换
- C++20字符串文本模板参数工作示例
- C++中的可变参数模板及其工作原理
- std::bind,无法让具有单个参数的方法工作
- 隐式转换是否应该在模板参数的上下文中工作?
- 我不明白参数和参数如何协同工作
- 通过参数启用时,std::enabled_if 如何工作
- 当传递NULL作为参数时,函数重载是如何工作的
- GoogleTest 中的参数化测试无法按预期工作
- 此函数如何在不传递任何参数的情况下工作?
- 我的代码在作为参数传入 .begin() 时不起作用,但在我将 .begin() 转换为迭代器后工作
- C++11: 如何编写一个像 Get 一样工作的模板函数<tuple>...但是收到参数包?
- 参数传递和返回值如何在程序集级别的 x86 上的 C/C++ 中工作?
- 我可以更改将引用参数传递到指针中并使其正常工作的函数的输入(C、C++)吗?
- 工作函数重载如何使用可变参数解析?
- 宏参数的扩展如何在 c++ 中工作
- 'const std::string&s = nullptr' 如何作为可选参数工作
- C++输入重定向导致文件参数工作时出错
- 获取浮点模板参数工作编译的"hack",但在 g++ 和 clang 上都存在段错误