如何摆脱这些警告?

时间:2015-04-16 04:59:39

标签: c++

#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;
 }

这是我的main.cpp 当我运行这段代码时,它显示了在iFood上调用的删除警告,它是抽象的,但是具有非虚拟析构函数。

1 个答案:

答案 0 :(得分:1)

您需要在virtual中创建析构函数iFood

请参阅Why do we need a pure virtual destructor in C++?了解原因。