c++构造与析构函数

来源:互联网 发布:三星gear2软件下载 编辑:程序博客网 时间:2024/04/28 07:53

#include "iostream.h"
#include "string.h"
class base
{
public:
 
 base( const char *p)
 {
  strcpy(t,p);
  cout<<p<<"  base Constructed! "<<endl;
 }
 ~base()
 {
  cout<<t<<"  base Deconstruct! "<<endl;
 }
 void get()
 {
  cout<<"base t:"<<t<<endl;
  cout<<"base w:"<<w<<endl;
 }
 
private :
 static int w;
 char t[20];
 
};
int base::w=23;    //静态成员必须被初始化(在类外)


void main()
{
 base k("Object K ");
 k.get();
 
}