我是一个完全的初学者,我已经在论坛上阅读了关于这个主题的各种帖子,但我仍然不确定我哪里出错了。
这是我的基类:
class room {
protected:
int doors;
string name;
room *north;
room *east;
room *south;
room *west;
public:
room(int numDoors, string rmName);
virtual string getName();
virtual void setRoom(int numDoors, string rmName);
void setConnect(room *room1, room *room2, room *room3, room *room4);
};
room::room(int numDoors, string rmName) : doors(numDoors), name(rmName) {}
string room::getName() {
return this->name;
}
void room::setConnect(room *room1, room *room2, room *room3, room *room4) {
this->north = room1;
this->east = room2;
this->south = room3;
this->west = room4;
return;
}
这是我的派生类:
class treasureRoom : public room {
protected:
string chest[5];
public:
treasureRoom() : base(4, "The Mad King's Hoard") {}
void setChest(string &loot1, string &loot2, string &loot3, string &loot4, string &loot5);
string getChest(int i);
};
void treasureRoom::setChest(string &loot1, string &loot2, string &loot3, string &loot4, string &loot5) {
this->chest[0] = loot1;
this->chest[1] = loot2;
this->chest[2] = loot3;
this->chest[3] = loot4;
this->chest[4] = loot5;
return;
}
string treasureRoom::getChest(int i) {
return this->chest[i];
}
我已多次尝试在论坛上讨论有关此类错误的解决方案,但我仍然缺少一些至关重要的内容。任何帮助将不胜感激!
答案 0 :(得分:1)
完整的错误消息非常清楚发生了什么:
Undefined symbols for architecture x86_64:
"room::setRoom(int, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >)", referenced from:
vtable for room in asd-cc336a.o
vtable for treasureRoom in asd-cc336a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [asd] Error 1
您没有包含room::setRoom(...)
的定义。