20181025 C++

 

include <iostream>
include <string>
using namespace std;
class StudentID
{
public:
StudentID(int id=0)
{
value=id;
cout<<"Assigning student id "<<value<<endl;
}
~StudentID()
{
cout<<"Destructing id "<<value<<endl;
}
private:
int value;
};
class Student
{
public:
Student(char * pName="no name",int ssID=0):id(ssID)
{
cout<<"Constructing student "<<pName<<endl;
strncpy(name,pName,sizeof(name));
name[sizeof(name)-1]='\0';
}
~Student()
{
cout<<"Deconstructing student "<<name<<endl;
}
protected:
char name[20];
StudentID id;
};
void main()
{
Student s("wang",9901);
Student t("li");
}
xiaotmh

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: