我从我写的一个类中得到了一些非常奇怪的链接错误。我完全找不到任何可以描述正在发生的事情的东西。
视觉工作室 (Windows XP)
player.obj:错误 LNK2019:未解析的外部符号“public: __thiscall TreeNode::TreeNode(void)”(??0?$TreeNode@VPlayer@@@@QAE@XZ) 在函数“public: __thiscall PlayerList::PlayerList”中引用(void)" (??0PlayerList@@QAE@XZ)
Xcode (OSX 10.5)
未定义符号:“TreeNode::~TreeNode()”,引用自:players.o 中的 PlayerList::~PlayerList()
头文件:generics.h
class TreeNode : public BaseNode{
public:
const static int MAX_SIZE = -1; //-1 means any size allowed.
const static int MIN_SIZE = 0;
//getters
int size() const;
vector<C*> getChildren() const;
//setters
void setChildren(vector<C*> &list);
//Serialization
virtual void display(ostream &out) const;
virtual void read(istream &in);
virtual void write(ostream &out) const;
//Overrides so SC acts like an array of sorts.
virtual C* get(int id) const;
virtual int get(C *child) const;
virtual bool has(C *child) const;
virtual C* pop(int id);
virtual void push(C *child);
virtual TreeNode& operator<< (C *child); //append
virtual void remove(int id); //Clears memory
virtual void remove(C *child); //Clears memory
//Initalizers
TreeNode();
TreeNode(istream &in);
TreeNode(long id, istream &in);
TreeNode(BaseNode* parent, istream &in);
TreeNode(long id, BaseNode* parent);
TreeNode(long id, BaseNode* parent, istream &in);
~TreeNode();
string __name__() const{ return "TreeNode"; }
protected:
void clearChildren();
void initalizeChildren();
vector<C*> _children;
};
来自 TreeNode 子类的代码
PlayerList::PlayerList() : TreeNode<Player>(){}
PlayerList::PlayerList(istream &in) : TreeNode<Player>(in){}
PlayerList::~PlayerList(){}