20181025 C++

发布于 2018-10-25  369 次阅读


 

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");
}

我们的征途是是星辰大海