'L'之前缺少模板参数
Missing template arguments before 'L'
本文关键字:参数 更新时间:2023-10-16
出现以下错误
[Error] missing template arguments before 'L'
[Error] 'L' was not declared in this scope
recipe for target 'main.o' failed
在这个代码部分
int main () {
lista L;
L.crealista();
这是什么意思?
这是类"lista":
template <class tipoelem>
class lista {
public:
typedef int pos;
struct cella {
tipoelem elemento;
pos prec;
pos succ;
};
lista ();
~lista ();
如果我们将其归结为基础,那么您就有了:
template <class T>
struct X{};
int main()
{
X x;
}
由于X是一个类模板,并且您没有为它提供T,因此您将收到一个错误,指出缺少模板参数。解决办法是为其提供适当的元素:
// ... as before ...
int main()
{
X<int> x; // Note <int> argument.
}
从你的简短片段来看,你似乎有一个链接列表(lista),你正在创建它,其中包含一些你想要存储的数据类型(tipoelem)。你需要说明列出你想要的tipoele姆。
例如
lista<int> L;
已修复!现在我正在尝试实现一个printlist函数。
在列表类头文件中添加了此项
void stampalista (lista& L);
和.cpp
template <class tipoelem>
void lista<tipoelem>::stampalista (lista& L) {
lista::pos corrente;
if (L.listavuota()) {
cout << "la lista e' vuotan";
return;
}
corrente = L.primolista();
while (!L.finelista(corrente)) {
cout << L.leggilista(corrente) << " ";
corrente = L.succlista(corrente);
}
cout << "n";
}
错误:
[错误]调用"lista::stampalista()"时没有匹配的函数
相关文章:
- 如何反转整数参数包
- 使用C++库在Android项目中修改gradle中的cmake参数,用于插入指令的测试
- 如何使用默认参数等选择模板专业化
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- lambda参数转换为constexpr技巧,然后获取带链接的数组
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 函数调用中参数的顺序重要吗
- 部分定义/别名模板模板参数
- 模板-模板参数推导:三个不同的编译器三种不同的行为
- 使用不带参数的函数访问结构元素
- 基于另一个成员参数将函数调用从类传递给它的一个成员
- 如何在OMNET++中指定与命令行参数组合的输出文件名
- 如何使用Luacneneneba API正确读取字符串和表参数
- 在派生函数中指定void*参数
- 视图中的参数推导失败:take_while
- static_assert在宏中,但也可以扩展到可以用作函数参数的东西
- 使用指向成员的指针将成员函数作为参数传递
- 没有名称的C++模板参数
- 如何将enable-if与模板参数和参数包一起使用