小编Gue*_*ham的帖子

C++使用模板编译错误

我有这个功能:

template <typename T>
List<T>::ListNode *List<T>::find(int index) const
{
    if ( (index < 1) || (index > getLength()) )
        return NULL;
    else
    {
        ListNode *cur = head;
        for (int skip = 1; skip < index; ++skip)
            cur = cur->next;
        return cur;
    }
}
Run Code Online (Sandbox Code Playgroud)

这给了我这两个错误,每个错误都在第二行:

expected constructor, destructor, or type conversion before '*' token
expected `;' before '*' token
Run Code Online (Sandbox Code Playgroud)

我使用模板的所有其他方法都可以正常工作.我认为问题是我调用ListNode结构的语法错误.我之前没有模板工作,现在我正在尝试用模板实现它,我收到这些错误.

c++ syntax templates

0
推荐指数
1
解决办法
100
查看次数

标签 统计

c++ ×1

syntax ×1

templates ×1