我想創建一個庫存鏈接列表,用戶可以在其中添加產品(id,info,price,count),然後將該對象存儲在鏈接列表中。 我遇到的問題是Node類給出的錯誤「缺少類型說明符 - int假定。注意:C++不支持default-int」等等。節點鏈接列表中的對象
#ifndef INVENTORY_H
#define INVENTORY_H
#include<iostream>
#include <string>
#include <iomanip>
using namespace std;
class Node
{
public:
Node(){}
Node(const Inventory& theData, Node *theLink)
: data(theData), link(theLink){}
Node* getLink() const { return link; }
Inventory getData() const { return data; }
void setData(const Inventory& theData)
{
data = theData;
}
void setLink(Node *theLink) { link = theLink; }
private:
Inventory data;
Node *link; //pointer that points to next node
};
class Inventory
{
public:
Inventory();
void addPart(int, string, int, int);
void findPart(int);
void toBinary();
void quit();
private:
int id;
int price;
string partInfo;
int partCount;
Node* first;
Node* last;
int count;
};
#endif
,並且錯誤是:
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(13): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(13): error C2143: syntax error : missing ',' before '&'
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(16): error C2146: syntax error : missing ';' before identifier 'getData'
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(16): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(16): warning C4183: 'getData': missing return type; assumed to be a member function returning 'int'
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(17): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(17): error C2143: syntax error : missing ',' before '&'
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(23): error C2146: syntax error : missing ';' before identifier 'data'
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(23): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(13): error C2065: 'Thedata' : undeclared identifier
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(13): error C2065: 'theLink' : undeclared identifier
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(13): error C2614: 'Node' : illegal member initialization: 'data' is not a base or member
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(16): error C2065: 'data' : undeclared identifier
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(19): error C2065: 'data' : undeclared identifier
1>c:\users\jeffrey\desktop\epp_fall\epp_fall\inventory.h(19): error C2065: 'theData' : undeclared identifier
剛剛使用'std :: list'或'std :: vector'有什麼問題?爲什麼重新發明輪子? –