# Include <iostream>
# Include <cstring>
Using namespace STD;
Class person
{
Char * Name;
Int age;
Char * address;
Public:
Person ();
Person (char * Name, char * address, int age );
~ Person ();
Void introduce ();
};
Class student: Public Person
{
Char * studentno;
Public:
Student ();
Student (char * Name, char * address, int age, char * studentno );
~ Student ();
Void introduce ();
};
Person: Person ()
{
Cout <"calling the person constructor" <Endl;
}
Person: Person (char * Name, char * address, int age)
{
This-> age = age;
This-> name = new char [strlen (name) + 1];
This-> address = new char [strlen (Address) + 1];
Strcpy_s (this-> name, strlen (name), name );
Strcpy_s (this-> address, strlen (address), address );
}
Person ::~ Person ()
{
Cout <"calls the person destructor" <Endl;
}
Void person: Introduce ()
{
Cout <* P <Endl;
Cout <"name is" <name <Endl;
Cout <"Age is" <age <Endl;
Cout <"address is" <address <Endl;
}
Student: Student ()
{
Cout <"Call student's constructor \ n ";
}
Student: Student (char * Name, char * address, int age, char * studentno): Person (name, address, age)
{
This-> studentno = new char [strlen (studentno) + 1];
Strcpy_s (this-> studentno, strlen (studentno), studentno );
}
Student ::~ Student ()
{
Cout <"calls student's destructor \ n ";
}
Void Student: Introduce ()
{
Person: Introduce ();
Cout <"studentno is" <studentno <Endl;
}
Int main ()
{
Return 0;
}
Author: Lin yufei
Source: http://www.cnblogs.com/zhengyuhong/
The copyright of this article is shared by the author and the blog Park. You are welcome to repost it. However, you must keep the author's information without the author's consent and provide the original article connection clearly on the article page.