如何观察C ++析构函数破坏基本数据类型?

问题描述

我有两个类,一个是主类,另一个是Test,对于Test类,我有Test.cpp和Test.h


//-----Test.h--------//
#pragma once
class Test
{
private:
    int num;
public:
    Test(void);
    Test(int n);
    ~Test(void);
};



//------Test.cpp------//

#include "Test.h"

#include<iostream>
using namespace std;


Test::Test(void)
{
}

Test::Test(int n)
{
    num = n;
}

Test::~Test(void)
{
    cout << "Deleted" << endl;
    cout << "num = " << num << endl ;
}


//---------main.cpp--------------//


#include "Test.h"

#include<iostream>
using namespace std;

int main()
{
    Test t1 = Test(5);
    return 0;
}

我期望的输出是

已删除

num = 0

但是实际输出是

已删除

数字= 5

为什么会这样,为什么析构函数会淡出内存 或dint删除基本数据类型,如何删除变量, 我可以用什么方法观察基本数据类型被删除?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)