C++ Programming, For Beginners, Quick Start Guide. by Docker Raspberry D. & Yao Ray

C++ Programming, For Beginners, Quick Start Guide. by Docker Raspberry D. & Yao Ray

Author:Docker, Raspberry D. & Yao, Ray [Docker, Raspberry D.]
Language: eng
Format: epub
Publisher: Step by Step Tutorial eBook & Book
Published: 2020-08-04T16:00:00+00:00


Example 5.10

#include <iostream>

using namespace std;

class A {

protected: // define protected permission

int prot; // declare a protected member

};

class B: A { // inheritance

public:

void myfunction(){

prot = 100 ; // access protected member, ok !

cout << prot;

}

};

int main(){

B obj;

obj. myfunction();

return 0;

}

Output:

100

Explanation:

“protected: int prot;” declares a protected member.

“prot = 100;” access protected member of the base class, because the protected member in base class can be accessed by derived class.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.