|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#ifndef CONS_DES_H
#define CONS_DES_H
//头文件
#include <iostream>
class base
{
public:
base(int);
~base();
private:
int data;
};
#endif
#include "cons_des.h"
//.cpp 文件
base::base(int value):data(value)
{
std::cout << "Object" << data << " constructor";
}
base::~base()
{
std::cout << "Object" << data << " destructor" << std::endl;
}
//main函数的主文件(,cpp)
#include "cons_des.h"
using namespace std;
void create(void);
base first(1);
int main()
{
cout << " (globally created before main) " << endl;
base second(2);
cout << " (local automatis in main) " << endl;
static base third(3);
cout << " (local static in main) " << endl;
create();
base sixth(6);
cout << " (local automatic in main) " << endl;
return 0;
}
void create(void)
{
base fourth(4);
cout << " (local automatic in create) " << endl;
static base fifth(5);
cout << " (local static in create) " << endl;
}
//运行结果:
Object1 constructor (globally created before main)
Object2 constructor (local automatis in main)
Object3 constructor (local static in main)
Object4 constructor (local automatic in create)
Object5 constructor (local static in create)
Object4 destructor
Object6 constructor (local automatic in main)
Object6 destructor
Object2 destructor
Object5 destructor
Object3 destructor
问题:为什么最后的应该是调用first对象的析构函数啊 。为什么没有显示呢。就差这一个。求鱼油们帮忙。 |
|