【发布时间】:2010-11-20 10:41:41
【问题描述】:
以下是链表头文件:
// 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;
};
酒厂 ctor 有 4 个参数,如下所示:
// 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 init 列表进行初始化 私有成员变量。
//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
}
然后我们去链表:
//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: unresolved external symbol "public: __thiscall list::node::node(class winery const &)" (??0node@list@@QAE@ABVwinery@@@Z) 引用函数“公共:void __thiscall list::insert(class winery const &)”(?insert@list@@QAEXABVwinery@@@Z)
因为节点ctor是链表私有的结构? list.cpp?
【问题讨论】:
-
酒厂在哪里申报?我可以看看声明吗?
-
#ifndef WINERY #define WINERY #include
class winery { public: winery(const char * const name, const char * const位置,常量 int 英亩,常量 int 等级);虚拟〜酒厂(无效); const char * const getName() const; const char * const getLocation() const;常量 int getAcres() 常量;常量 int getRating() 常量; // 显示酒厂列表的标题 static void displayHeadings(std::ostream& out);朋友 std::ostream& operator
标签: c++