【求解】未定义的析构函数
生活随笔
收集整理的這篇文章主要介紹了
【求解】未定义的析构函数
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
abc說(shuō)明:定義 del 函數(shù)的時(shí)候,abc 的析構(gòu)函數(shù)未定義,因此不會(huì)調(diào)用。看如下代碼,試解釋器運(yùn)行結(jié)果
#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;
}
編譯出現(xiàn)警告
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
說(shuō)明:定義 del 函數(shù)的時(shí)候,abc 的析構(gòu)函數(shù)未定義,因此不會(huì)調(diào)用。感覺(jué)有說(shuō)服力么?
轉(zhuǎn)載于:https://www.cnblogs.com/westfly/archive/2011/09/15/2177259.html
總結(jié)
以上是生活随笔為你收集整理的【求解】未定义的析构函数的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ASP.NET 无限级分类实现实例(深度
- 下一篇: 关于C#调用API的理解(汇多考勤机HD