现在的位置: 首页 > 综合 > 正文

C++笔试题 关于函数析构函数未调用的问题

2013年05月13日 ⁄ 综合 ⁄ 共 440字 ⁄ 字号 评论关闭

// 请说出如下代码的输出

#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 .

抱歉!评论已关闭.