#include <iostream>
#include <string.h>
using namespace std;
class Person
{
private:
int m_age;
char* m_name;
public:
Person();
Person(char* name, int age)
{
strcpy(this->m_name,name);
this->m_age = age;
}
~Person();
void setname(char* name)
{
strcpy(this->m_name, name);
}
void setage(int age)
{
this->m_age = age;
}
void getname()
{
cout<<"my name is :"<<this->m_name<<endl;
}
void getage()
{
cout<<"my age is:"<<this->m_age<<endl;
}
};
class Student:public Person
{
private:
int m_class;
public:
Student(char *name , int age , int room):Person(name,age)
{
this->m_class = room;
};
void setclass(int room)
{
this->m_class = room;
}
void getclass()
{
cout<<"my class is "<<this->m_class<<endl;
}
void disp()
{
this->getage();
this->getclass();
this->getname();
}
};
int main()
{
Person *p1 = new Person("som",18);
p1->getage();
p1->getname();
Student *s1 = new Student("abab",20,1);
s1->disp();
}
输出结果如下,只有p1的输出没有s1的输出
