0
#include <iostream>
 #include "Pizza.h"

int main() {

 iFood* food;

food = new Pizza(14.0, 8);

 for (int i = 0; i < 3; i++)
     food->consume();
 food->display();
 std::cout << std::endl;

 delete food;

 food = new DeluxePizza(12.0, 6, "mushrooms, peppers");

 for (int i = 0; i < 2; i++)
     food->consume();
 food->display();
 std::cout << std::endl;

 delete food;
 }

This is my main.cpp when I run this code, it shows the warning that delete called on iFood that is abstract but has non-virtual destructor.

Adi
  • 13
  • 1
  • 5
  • #include class iFood{ public: virtual void consume()=0; virtual void display() const=0; }; – Adi Apr 16 '15 at 04:59
  • You shouldn't be using `new` here in the first place. C++ is not Java, don't try to blindly copy things you learned there. – Ulrich Eckhardt Apr 16 '15 at 05:11

1 Answers1

1

You need to make the destructor virtual in iFood.

See Why do we need a pure virtual destructor in C++? to understand why.

Community
  • 1
  • 1
R Sahu
  • 204,454
  • 14
  • 159
  • 270