在class computer的析构函数中的三个if语句中的delete会有警告提示(delete called on 'VIDEOCARD' that is abstract but has non-virtual destructor [-Wdelete-non-virtual-dtor]),void test1()中的delete却没有报警。在vs2019中4个delete均没有警告提示,请问是不是我的vscode配置有问题,还请各位指点一下,我应该如何修改vscode的配置
#include <iostream>
#include <string>
using namespace std;
//create abstract base class
class CPU{
public:
virtual void process() = 0;//接口
};
class VIDEOCARD{
public:
virtual void display() = 0;
};
class MEMORY{
public:
virtual void storage() = 0;
};
//generate a computer
class computer{
public://构造函数初始化对象
computer(CPU *cpu, VIDEOCARD *videocard, MEMORY *memory)//作用是CPU *m_cpu= new interorlenovo
{
cout << "构造函数调用" << endl;
m_cpu = cpu;
m_videocard = videocard;
m_memory = memory;
}
~computer(){
cout << "析构函数调用" << endl;
if (m_cpu != NULL)
{
delete m_cpu; //这三个if语句中的delete会有报警提示
cout << "delete m_cpu done" << endl;
}
if (m_videocard != NULL)
{
delete m_videocard;
cout << "delete m_videocard done" << endl;
}
if (m_memory != NULL)
{
delete m_memory;
cout << "delete m_memory done" << endl;
}
}
public:
CPU *m_cpu;
VIDEOCARD *m_videocard;
MEMORY *m_memory;
};
//specify factory to generate the part of computer
class intercpu: public CPU{
public:
virtual void process(){//具体实现
cout << "使用inter cpu组装电脑" << endl;
}
};
class intervideocard: public VIDEOCARD{
public:
virtual void display(){//具体实现
cout << "使用inter 显卡组装电脑" << endl;
}
};
class intermemory: public MEMORY{
public:
virtual void storage(){//具体实现
cout << "使用inter 内存条组装电脑" << endl;
}
};
//测试例子
void test0(){
CPU *Cpu = new intercpu;
VIDEOCARD *Videocard = new intervideocard;
MEMORY *Memory = new intermemory;
computer Computer(intercpu, intervideocard, intermemory);
Cpu->process(); Videocard->display(); Memory->storage();
// delete
}
void test1(){
computer * com = new computer(new intercpu, new intervideocard, new intermemory);
com->m_cpu->process(); com->m_videocard->display(); com->m_memory->storage();
delete com; //这里没有报警
}
int main(){
test0();
cout << "-————————————————————————————————————" << endl;
test1();
return 0;
}
在class computer的析构函数中的三个if语句中的delete会有警告提示(delete called on 'VIDEOCARD' that is abstract but has non-virtual destructor [-Wdelete-non-virtual-dtor]),void test1()中的delete没有警报提示。在vs2019中4个delete均没有警告提示,请问是不是我的vscode配置有问题,还请各位指点一下,我应该如何修改vscode的配置