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”);
}
分享到:
赞(0)

评论抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

你好鸭!

啦啦啦