Answers for "calling base class function from derived class object"

C++
0

calling base class function from derived class object

#include <iostream>
#include <string>

using namespace std;

class Person{
public:
    void introduce(){
    cout <<"hey from person"<<endl;
    }
};

class Student : public Person{
public:
    void introduce(){
    cout <<"hey from student"<<endl;
    }
};

void whosThis(Person &p){
p.introduce();
}

int main()
{
    Student anil;
    anil.introduce();
    whosThis(anil);
    return 0;
}
Posted by: Guest on May-14-2021

Code answers related to "calling base class function from derived class object"

Browse Popular Code Answers by Language