Answer to Question #264308 in C++ for Amit

Question #264308

(Pointers to derived classes) Write a program to illustrate how pointers to a base class is used for both base and derived class.


1
Expert's answer
2021-11-12T16:32:05-0500
#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);
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS