jeudi 12 décembre 2019

Using a unique pointer to call a function crashes my program

I made a really simple program to try fusing unique pointers and inheritance together. But, it ends up crashing with exit code 11 and I don't know why. Can Anyone explain the reason for the crash?

//Counter Class, Base class
class Counter {
   public:
    virtual int addStuff(int& x)=0;
  };
//Derived Class, child class of Counter
class Stuff:public Counter {
 public:
  virtual int addStuff(int& x) override;
};
//Main function using unique pointers to call addStuff from Stuff class
int main() {
  int x = 12;
  std::unique_ptr<Stuff> p;
  p->addStuff(x);
}

Aucun commentaire:

Enregistrer un commentaire