Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1567915
  • 博文数量: 354
  • 博客积分: 8137
  • 博客等级: 中将
  • 技术积分: 5137
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-26 15:40
文章分类

全部博文(354)

文章存档

2010年(300)

2009年(54)

分类: C/C++

2010-03-07 00:55:50

#include
#include

using namespace std;
class CStudent
{
        public:
            CStudent();
            CStudent(char *name,int age);
            ~CStudent();
            void init(char *name,int age);
            void output();
        
        private:
            char m_name[20];
            int m_age;
};

CStudent::CStudent()
{
           strcpy(m_name,"TOM");
           m_age = 0;
}

CStudent::CStudent(char *name,int age)
{
        strcpy(m_name,name);
        m_age = age;
}

CStudent::~CStudent()
{
    cout<<"The object is deconstructing!"<}

void CStudent::init(char *name,int age)
{
        strcpy(m_name,name);
        m_age = age;
}

void CStudent::output()
{
        cout<< m_name <<"               " <}

int main()
{
        CStudent stu1;
        CStudent *p = &stu1;
        p->init("Peg",22);
        (*p).output();

        return 0 ;
}

明白,析构函数的特性,用法。
阅读(655) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~