遇到 unexpected type 不懂什么意思,求教!!

hello_tony hello_tony 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
写一个一个链表的程序:

LinearList.h 如下

#include<iostream>

class ListNode
{
public:
int key;
ListNode *next;
ListNode():next(NULL){}
ListNode(int x):key(x),next(NULL){}
~ListNode();

};

class LinearList
{

private:
int size;
ListNode *head;

public:
LinearList(void) ;
~LinearList(void);
bool insert(int x, int pos);
bool remove(int &x, int pos);
int element(int pos) const;
int search(int x) const;
int length() const;
(ListNode*) find(int i)const;
};

LinearList.cpp 如下

#include"LinearList.h"


LinearList::LinearList(void)
{
size = 0;
head = new ListNode();
head->next = NULL;
}

(ListNode*) LinearList::find(int i) //此处有错,见下面的error
{
ListNode *node = head;
int x = 0;
while ((x++<i)&&(node!=NULL))
node = node->next;
return node;
}

bool LinearList::insert(int x, int pos)
{
if(x<0 || x>size)
{
std::cout<<"ArrayOutOfBound!";
return false;
}

ListNode *node = new ListNode(x);
ListNode *cur = find(pos);
node->next = cur->next;
cur->next = node;
size++;
return true;
}

bool LinearList::remove(int &x, int pos)
{
if(x<=0 || x>size)
{
std::cout<<"ArrayOutOfBound!";
return false;
}

ListNode *pre = find(pos-1);
ListNode *del = pre->next;
x = del->key;
pre->next = del->next;
delete del;
size--;
return true;

}

int LinearList::element(int pos) const
{
if(pos<=0 || pos>size)
{
std::cout<<"ArrayOutOfBound!";
return 0;
}

ListNode *cur;
cur = find(pos);
return cur->key;
}

//查找值为x的元素,返回元素的位置(第一个元素的位置为1)。未找到时返回0。
int LinearList::search(int x) const
{
int i = 1;
ListNode *itr = head->next;
while(itr!=NULL && itr->key!=x)
{
itr = itr->next;
i++;
}
return i;
}

inline int LinearList::length() const
{
return size;
}



编译报错:
error C2226: syntax error : unexpected type 'ListNode'
error C2143: syntax error : missing ';' before '{'
error C2447: '{' : missing function header (old-style formal list?)

小弟学习c++不久,望高手不吝赐教~~~~
...全文

相关推荐

Vue项目报错:Uncaught SyntaxError: Unexpected token

遇到问题: 今天做一个 VUE 的项目,在引入第三方依赖的 JS 文件时,遇到了一个问题: 控制台的提示:Uncaught SyntaxError: Unexpected token &lt; 按照提示进入文件,再看如下图: 仔细看了看 index.html 文件,发现原本我的 JS 文件是放在 /src/utils 文件夹下的,但引入 /src 和 /static 的文件是有区别的。 解决方案: 解决办法是将第三方依赖的 JS 文件放到 /static/utils 目录下,引入路径也改成:[removed][removed],这样就

weixin_38697328

JS提示:Uncaught SyntaxError: Unexpected token ILLEGAL错误的解决方法

本文实例讲述了JS提示:Uncaught SyntaxError: Unexpected token ILLEGAL错误的解决方法。分享给大家供大家参考,具体如下: Uncaught SyntaxError: Unexpected token ILLEGAL 未捕获的语法错误: 意想不到的非法令牌 如下图所示: 复制代码 代码如下:&lt;input id=”btn_0_4EAE4F474C91156086C0D4EA7E983C69C215B649″ type=”button” value=”连接” onclick=”middleware_connect(0, 4EAE4F474C911560

weixin_38699593

VB dll(Unexpected error)

To fixup vb unexpected error.

boren31

Module parse failed: Unexpected token

Module parse failed: Unexpected token 问题描述 学习React出现的一个问题 从官网拿到的一个例子 class HelloMessage extends React.Component { render() { return ( Hello {this.props.name} ); } } ReactDOM.render( , document.getElementById('hello-example') ); 在用webpack打包时报错 RR

weixin_38535221

vue-cli 打包后提交到线上出现 "Uncaught SyntaxError:Unexpected token" 报错

主要介绍了vue-cli 打包后提交到线上出现 "Uncaught SyntaxError:Unexpected token" 报错,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧

weixin_38682406
评论 6
收藏 已收藏
分享
返回顶部
hello_tony
C++ 语言 65,214 成员 250,514 内容