我只是切换到C++,从C# 我写C++中的链接列表的代码运行它在Win32控制台应用程序时遇到非常奇怪的错误,同时建立代码的行为很奇怪
我在评论中指出的3个错误,其余的我不能打字,太多了。
using namespace std;
class float_list
{
struct node
{
double data;
struct node *next;
};
node *head;
public:
float_list(void)
{
head = nullptr;
};
void appendNode(double);
};
//void float_list::appendNode(float num)
//{
//
//}
void float_list::appendNode(double num)
{
node *newNode;
node *ptr; //here i am getting this Error error C3872:
//'0xa0': this character is not allowed in an identifier ,
// how ever I changed its name again and again.
newNode = new node;
newNode->data = num; // here un declared identifier ,
//also missing ; before this line
newNode->next = nullptr;
if (!head)
{
head = newNode;
}
else
{
ptr = head;
while (ptr->next)
{
ptr = ptr->next;
ptr->next = newNode;
};
}
}
你从一个HTML页面复制粘贴? IIRC,0xa0是nbsp。 – ninjalj 2012-02-24 18:39:44
您是否复制了以Unicode格式保存的任何代码? '0xa0'是一个不间断的空间,可能无法被编译器识别。 – Foggzie 2012-02-24 18:42:12
在上一个'while'循环中有一个错误:'ptr-> next = newNode;'应该在循环外*。另外,最好为列表维护* head *和* last *节点指针;这样你就不需要在每个新的'appendNode'上重复遍历整个列表。 – 2012-02-24 18:50:34