0

I have the following two 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 the main I want to create a vector that stores pointers to Grill objects. So I create vector<Grill*>. The problem is when I create an object. My 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 as well, not compiled

   return 0;
}

The g++ shows the following errors:

In function `Grill::Grill(std::string, float)':
program6.cc:(.text._ZN5GrillC2ESsf[_ZN5GrillC5ESsf]+0x1c): undefined reference to `vtable for Grill'
/tmp/ccjLugR9.o: In function `Grill_Charcoal::~Grill_Charcoal()':
program6.cc:(.text._ZN14Grill_CharcoalD2Ev[_ZN14Grill_CharcoalD5Ev]+0x1f): undefined reference to `Grill::~Grill()'
/tmp/ccjLugR9.o: In function `Grill::Grill(Grill const&)':
program6.cc:(.text._ZN5GrillC2ERKS_[_ZN5GrillC5ERKS_]+0x17): undefined reference to `vtable for Grill'
/tmp/ccjLugR9.o:(.rodata._ZTI14Grill_Charcoal[_ZTI14Grill_Charcoal]+0x10): undefined reference to `typeinfo for Grill'
collect2: error: ld returned 1 exit status

Any explanation why this happen?

0

1 Answer 1

1

The error message spells it out for you ... you declared ~Grill() but you never defined it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.