Private Inheritance in c++





This video tutorial explains the private inheritance in c++.

You will learn what is private inheritance, what is the use of private inheritance, what happens to class members when private inheritance is used to inherit from the base class, how to access the members in derived class when private inheritance is used in detail with example.

source code for this tutorial

 

#include <iostream>
#include <string>

using namespace std;

class Person{
protected:
    string name;
public:
    void setName(string iname){
    name = iname;
    }
};

class Student : private Person{
public:
    void display(){
    cout << name<<endl;
    }
    void studentSetName(string iname){
    setName(iname);
    }
};

class GStudent : public Student{
public:
    void setGStudentName(string iname){
    studentSetName(iname);
    }
};
int main()
{
    GStudent anil;
    anil.setGStudentName("anil");
    anil.display();
    return 0;
}

Back To Top