C++ Programming, For Beginners, Learn Coding Fast! by Yao Ray

C++ Programming, For Beginners, Learn Coding Fast! by Yao Ray

Author:Yao, Ray [Yao, Ray]
Language: eng
Format: epub
Publisher: Ray Yao 's eBooks & Books
Published: 2020-03-22T16:00:00+00:00


Protected Permission

“protected” is one of the “Member Access Specifier”,.

protected class member can be accessed by the object in the current class and derived class, but not in another class.

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;

}



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.