c++ - undefined reference to vtable after the creation of a class object -
this question has answer here:
i have following 2 classes:
class grill { public: virtual ~grill(); virtual std::string get_model() const{return _model;}; virtual void set_price(float p){_price=p;}; virtual float get_price() const {return _price;}; virtual grill* clone()=0; protected: grill(std::string m,float p):_model(m),_price(p){}; grill(const grill& obj)=default; grill(grill&& obj)=default; std::string _model; float _price; private: grill& operator=(const grill& obj)=delete; }; class grill_charcoal final : public grill { public: grill_charcoal(std::string m,float p):grill(m,p){}; ~grill_charcoal(){}; grill_charcoal* clone() override{return new grill_charcoal(*this);}; protected: grill_charcoal(const grill_charcoal& obj)=default; grill_charcoal(grill_charcoal&& obj)=default; private: grill_charcoal& operator=(const grill_charcoal& obj)=delete; };
in main want create vector
stores pointers grill objects. create vector<grill*>
. problem when create object. main is:
int main() { using namespace std; vector<grill*> grill; grill_charcoal* gp=new grill_charcoal("adsaas",2312); //error //grill.push_back(new grill_charcoal("sdsaa",22)); //error well, not compiled return 0; }
the g++ shows following errors:
in function `grill::grill(std::string, float)': program6.cc:(.text._zn5grillc2essf[_zn5grillc5essf]+0x1c): undefined reference `vtable grill' /tmp/ccjlugr9.o: in function `grill_charcoal::~grill_charcoal()': program6.cc:(.text._zn14grill_charcoald2ev[_zn14grill_charcoald5ev]+0x1f): undefined reference `grill::~grill()' /tmp/ccjlugr9.o: in function `grill::grill(grill const&)': program6.cc:(.text._zn5grillc2erks_[_zn5grillc5erks_]+0x17): undefined reference `vtable grill' /tmp/ccjlugr9.o:(.rodata._zti14grill_charcoal[_zti14grill_charcoal]+0x10): undefined reference `typeinfo grill' collect2: error: ld returned 1 exit status
any explanation why happen?
the error message spells out ... declared ~grill() never defined it.
Comments
Post a Comment