Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- class Person{
- protected:
- string name;
- int age;
- public:
- Person(string name, int age){this->name = name;this->age = age;}
- virtual void showInfo(){
- cout<<"Person: "<<this->name<<"\t"<<this->age<<endl;
- }
- };
- class Student: public Person{
- public:
- Student(string name, int age):Person(name, age){}
- void showInfo(){
- cout<<"Student: "<<this->name<<"\t"<<this->age<<endl;
- }
- };
- void showVectior(vector<Person*> v){
- for(vector<Person*>::iterator it = v.begin(); it!=v.end(); it++)
- (*it)->showInfo();
- }
- int main(){
- vector<Person*> v;
- v.push_back(new Person("P1", 10));
- v.push_back(new Person("P2", 20));
- v.push_back(new Student("S1", 20));
- v[2]->showInfo();
- cout<<"\n\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment