(Pointers to derived classes) Write a program to illustrate how pointers to a base class is used for both base and derived class.
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Person {
public:
void Print() {
cout << "print" << endl;
}
private:
int size;
};
class Teacher : public Person {
public:
void PrintT() {
cout << "teacher" << endl;
}
private:
int age;
};
void print(Person* P) {
P->Print();
}
int main() {
Person P;
Teacher T;
print(&T);
}
Comments
Leave a comment