#include<iostream>
using namespace std;

class School
{
private:
    char*sname;
    int snumber,score;
public:

    void show( )
    {cout<<"sname is:"<< sname<<endl;
    cout<<"snumber is:"<< snumber<<endl;
    cout<<"score is:"<< score<<endl;
    }

    School(char*a,int xnumber,int xscore)
    {cout<<"有  参数的初始化"<<endl;
        sname=a;snumber=xnumber;score=xscore;}

    School()
    {cout<<"无  参数的初始化"<<endl;
    sname="no name";
    snumber=0;score=0;
    }

    School(const  School& s1)
    {cout<<"拷贝函数的初始化"<<endl;
        sname=new char[strlen(s1.sname)+1];
    strcpy(sname,s1.sname);
    snumber=s1.snumber,score=s1.score;
    }
    ~School()
    { cout<<"使用了析构函数"<<endl;
        delete []sname ;}


};

    void main()
    {
        School y1("华大",20110501,550),y2(y1),y3(y1);
        y1.show( );
        y2.show( );
        y3.show( );
    }

posted on 2013-02-23 16:01  叶城宇  阅读(139)  评论(0编辑  收藏  举报