鑑於此程序:如何刪除具有派生類對象中沒有dstructor
struct Base
{
virtual void f() {}
};
struct Derived:public Base
{
};
int main()
{
Derived* c = new Derived;
delete c;
}
GCC-4.4 -Wall是好的,但GCC-5.2 -Wall給出了警告:派生態類型」的刪除對象'具有非虛擬析構函數可能會導致未定義的行爲[-Wdelete-non-virtual-dtor]
我看到了the discussion on deleting a base pointer但在我的情況下,它是派生的對象。我認爲這是一個海灣合作委員會的錯誤,但顯然GNU doesn't think so。有沒有辦法在不改變基類定義的情況下襬脫警告?
該代碼是正確的;你可以忽略這個警告。 –