我必須爲大學作業寫一個鏈表,我已經按照我的說明遵循了對T的指示。鏈接列表錯誤:語法錯誤:缺少';'在標識符'head'之前
我想不通,爲什麼我得到的錯誤,它是與我listOfDouble類中聲明的指針,
心中已經通過搜索有關該錯誤消息堆棧的答案和一些帖子建議這可能是我的#包括一個問題,我應該聲明類:class ListOfDoubles;
我已經嘗試更換我的包括無濟於事。
我被困在這一點上,考慮到我是一名學生,所以我的錯誤可能最終變得微不足道。
編輯:這是微不足道的。
ListOfDoubles.h
#ifndef LISTOFDOUBLES_H
#define LISTOFDOUBLES_H
class ListOfDoubles{
public:
ListOfDoubles();
~ListOfDoubles();
void insert(double);
void displaylist();
double deleteMostRecent();
private:
DoubleListNodePtr head;
DoubleListNodePtr temp;
DoubleListNodePtr newNode;
};
#endif
DoubleListNode.h
#ifndef DOUBLELISTNODE_H
#define DOUBLELISTNODE_H
class DoubleListNode{
friend class ListOfDoubles;
public:
DoubleListNode(double);
private:
double data;
DoubleListNode *next;
};
typedef DoubleListNode* DoubleListNodePtr;
#endif
實施
#include "ListOfDoubles.h"
#include "DoubleListNode.h"
#include<iostream>
using std::cout;
ListOfDoubles::ListOfDoubles()
:head(NULL){
};
DoubleListNode::DoubleListNode(double data)
:data(data){
};
void ListOfDoubles::insert(double data){
newNode = new DoubleListNode(data);
newNode->next = head;
head = newNode;
};
void ListOfDoubles::displaylist(){
DoubleListNodePtr temp = head;
while (temp != NULL){
cout << temp->data;
temp = temp->next;
}
};
double ListOfDoubles::deleteMostRecent(){
};
ListOfDoubles::~ListOfDoubles(){
delete head;
delete temp;
delete newNode
};
主要
#include "ListOfDoubles.h"
#include "DoubleListNode.h"
#include<iostream>
int main()
{
ListOfDoubles list1;
list1.insert(25);
list1.displaylist();
system("pause");
return(0);
}
個
錯誤
1> main.cpp
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(13): error C2146: syntax error : missing ';' before identifier 'head'
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(14): error C2146: syntax error : missing ';' before identifier 'temp'
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(14): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(15): error C2146: syntax error : missing ';' before identifier 'newNode'
1>d:\college\semester 5\algorithms and data structures\lab_6b\lab_6b\lab_6b\listofdoubles.h(15): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
怎麼樣,包括'DoubleListNodePtr.h'在'ListOfDoubles.h'?或者至少爲該指針提供前向聲明和typedef? – 2014-10-30 20:46:30
沒關係,我認爲修復它。 – Johntk 2014-10-30 20:53:05