'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()"时没有匹配的函数