以下是鏈表的頭文件:私人節點構造函數中LL麻煩
// list.h
class list
{
public:
list(void); // constructor
virtual ~list(void); // destructor
void displayByName(ostream& out) const;
void displayByRating(ostream& out) const;
void insert(const winery& winery);
winery * const find(const char * const name) const;
bool remove(const char * const name);
private:
struct node
{
node(const winery& winery); // constructor
winery item;
node * nextByName;
node * nextByRating;
};
node * headByName;
node * headByRating;
};
酒廠構造函數有4 PARAM的如下:
// code in main.cpp
// this statement is very important
// I am trying to add the info to the list as a reference to the node ctor
wineries->insert(winery("Lopez Island Vinyard", "San Juan Islands", 7, 95));
我執行代碼爲止。
我調試,它把我帶到ctor。我使用ctor初始化列表來初始化私人成員變量 。
//winery.cpp
winery::winery(const char * const name, const char * const location, const int acres, const int rating)
: name(new char[strlen(name)+1]), location(new char[strlen(location)+1]), acres(0), rating(0)
{
// arcres, name, location, rating, are all private members of the winery class
}
然後我們去的LinkedList:
//list.cpp
void list::insert(const winery& winery)
{
list *ListPtr = new list();
// here im trying to add all the info to the list:
node *NodePtr = new node(winery);
}
我得到一個鏈接錯誤:LNK2019:無法解析的外部符號 「公用:__thiscall目錄::節點::節點(級酒莊常量&)」 (?插入@列表@@ QAEXABVwinery @@@ Z)
(參見函數「public:void __thiscall list :: insert因爲節點ctor是一個鏈接列表專用的結構? list.cpp?
酒莊在哪裏申報?我可以看到聲明嗎? – jkeys 2009-08-18 00:47:02
的#ifndef _WINERY_ 的#define _WINERY_ 的#include 級酒莊 { 市民: \t酒莊(爲const char * const的名字,爲const char * const的位置,const int的畝,const int的等級); \t虛擬酒莊(虛空); \t const char * const getName()const; \t const char * const getLocation()const; \t const int getAcres()const; \t const int getRating()const; \t //顯示標題爲酒莊的名單 \t靜態無效displayHeadings(STD :: ostream的& out); \t朋友的std :: ostream的和運營商<<(STD :: ostream的進出,釀酒* W); 私人: \t字符\t *名稱; \t字符\t *位置; \t INT 英畝; \t INT \t \t等級; }; #endif –
user40120
2009-08-18 04:45:15