【求解】未定义的析构函数
生活随笔
收集整理的這篇文章主要介紹了
【求解】未定义的析构函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
abc說明:定義 del 函數的時候,abc 的析構函數未定義,因此不會調用。看如下代碼,試解釋器運行結果
#include <stdio.h>class abc;
void del(abc *pobj)
{
delete pobj;
}
class abc{
public:
abc()
{
printf("abc\r\n");
}
~abc()
{
printf("~abc\r\n");
}
};
int main(int argc, char *argv[])
{
abc *pobj = new abc;
del(pobj);
return 0;
}
編譯出現警告
C:\Users\Ares\Desktop>g++ test.cpptest.cpp: In function `void del(abc*)':
test.cpp:5: warning: possible problem detected in invocation of delete operator:
test.cpp:4: warning: `pobj' has incomplete type
test.cpp:2: warning: forward declaration of `struct abc'
test.cpp:5: note: neither the destructor nor the class-specific operator delete
will be called, even if they are declared when the class is defined.
test.cpp:27:2: warning: no newline at end of file
abc
說明:定義 del 函數的時候,abc 的析構函數未定義,因此不會調用。感覺有說服力么?
轉載于:https://www.cnblogs.com/westfly/archive/2011/09/15/2177259.html
總結
以上是生活随笔為你收集整理的【求解】未定义的析构函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ASP.NET 无限级分类实现实例(深度
- 下一篇: 关于C#调用API的理解(汇多考勤机HD