在下面的程序中,为什么不调用析构函数并且不显示析构函数语句? [英] In the below program , why the destructor is not called and the destructor statement is not displayed ?

查看:174
本文介绍了在下面的程序中,为什么不调用析构函数并且不显示析构函数语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<iostream.h>
#include<conio.h>

class x
{
      public:
             x()
             {
                 cout<<"constructor called";
             }
             void show()
             {
                  cout<<"Show() called";
             }
             ~x()
             {
                 cout<<"Destructor called";
             }
};

int main()
{
    x o;
    o.show();
    getch();
    return 0;
}

推荐答案

已通过执行程序进行了检查>所使用的编译器?我确定会调用析构函数.
Have checked by executing the program>Which compiler you are using?I am sure destructor will be called.


我敢打赌它被称为-您只是看不到它,因为它是在getch()函数之后执行的.
为什么不将getch()放在析构函数的末尾?然后您会看到该消息.
I bet it is called - you just don''t see it because it gets executed after the getch() function.

Why don''t you put a getch() at the end of your destructor? You''ll see the message then.


这篇关于在下面的程序中,为什么不调用析构函数并且不显示析构函数语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆