// 请说出如下代码的输出
#include "stdafx.h"
#include<iostream>
#include<windows.h>
using namespace std;
class abc;
void del(abc *pobj);
void del(abc *pobj)
{
delete pobj;
}
class abc
{
public:
abc(){cout<<"adc()"<<endl;}
~abc(){cout<<"~adc()"<<endl;}
};
int main()
{
abc *pobj = new abc;
del(pobj);
system("pause");
return 0;
}
// 输出: abc()
为什么没有输出~abc()呢?因为,del函数定义时,还未知到~abc()函数的定义,只是知道存在一个abc类.从编译器给出的警告信息中也可知道:
warning C4150: deletion of pointer to incomplete type 'abc'; no destructor called .