Granting Access to Base Class Member in Derived Class





This video tutorial made by the Learning Lad explains how to change the scope or access level of base class members in the derived class.
You will learn how to use access declaration to grant access to base class members in derived class 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:

    Person :: name;
    Person :: setName;

    void display(){
    cout << name<<endl;
    }
    void studentSetName(string iname){
        setName(iname);
    }

};


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

 
Back To Top