C++人間学生類

1287 ワード

#include<iostream>
#include<string>
#include<vector>
using namespace std;
class Person{
public:
 Person(string name1,int age){
  //name=new string;
  this->name=name1;
  this->age=age;
 }
  virtual void show(){
  cout<<name<<" "<<age;
 }
  virtual ~Person(){
  cout<<"person  "<<endl;
  }
private:
 string name;
 int age;
};
class Student:public Person{
public:
 Student(string name1,int age1,string number1):Person(name1,age1),number(number1){}
 void show(){
  Person::show();
  cout<<" "<<number<<endl;
 }
 virtual ~Student(){
  cout<<"student  "<<endl;
 }
private:
 string number;
};
int main(){
 //Person p("huanfeihong",27);
 Student s("huanfeihong",27,"0XXXE");
 Person p=s;
 p.show();

/*

Person *p;

Student s("zhangwuji",30,"XXXWS");

p=&s;

p->show();//   

*/
 system("pause");
 return 0;
}