Protected Inheritance in c++





This video tutorial explains the protected inheritance in c++.
You will learn what is protected inheritance, what is the use of protected inheritance, what happens to class members when protected inheritance is used to inherit from the base class, how to access the members in derived class when protected 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 : protected Person{
public:
    void display(){
    cout << name<<endl;
    }
    void setStudentName(string iname){
    setName(iname);
    }
};


int main()
{
Student anil;
anil.setStudentName("anil");
anil.display();
return 0;
}

 
Back To Top