我已经看到所有其他的答案这个错误,但我试过所有我能找到,仍然没有工作。未定义引用'派生类的vtable'
这里是我的代码:
class Train{
protected:
string myID;
int myCap;
int myPass;
char myType;
public:
Train(string str,int num): myID(str), myCap(num){myPass=0;}
virtual ~Train(){};
string getmyID(){return myID;}
int getmyCap(){return myCap;}
char getmyType(){return myType;}
virtual void showTrainInfo()=0;
virtual int getCost(string,string)=0;
virtual bool operator== (const string)=0;
};
class STrain: public Train{
public:
STrain(string str, int num): Train(str,num){myType='S';}
~STrain(){cout<<"Deleted Train:"<<myID<<endl;}
void showTrainInfo(){
cout << "Train ID: " << this->myID << endl;
cout << "Train Capacity: " << this->myCap << endl;
cout << "Train Type: " << this->myType << endl;
}
int getCost(string origin, string dest);
bool operator== (const string a){
bool compare = false;
if(myID.compare(a) == 0)
compare = true;
return compare;
}
};
的错误是在派生功能应变。我也尝试在基类Train中定义我的虚拟析构函数,但它仍然给出了同样的错误。
我看过的其他错误,Train中的虚函数没有定义,并且通过将{}
添加到虚函数来解决,但正如您所看到的,它不适用于我。任何建议或解释为什么会发生这种情况?
您是否在某个地方定义了'STrain :: getCost'? – 2015-04-04 04:41:16
尚未尽管我尝试评论所有'int getCost'出来,它并没有解决任何问题。我定义了'STrain :: getCost',它看起来好像处理了它。谢谢 – 2015-04-04 09:12:32