If access to a virtual function in a base class is a case, the derived class can redefine the access rights of the base class virtual function when it inherits the base class, and the instance verifies that it is correct.
It also shows that the override or redefinition of the function is not much related to the previous access permission modification.
Base.h
#pragma once#include <iostream>using namespace Std;class base{public:base (void) {}~base (void) {}virtualvoid fun ( ) {cout<< "This is Base::fun" <<ENDL;} virtual void func () = 0;};
Son.h
#pragma once#include "base.h" class Son:p ublic Base{public:son (void) {}~son (void) {}virtual void fun () {cout<< " This is a son function "<<ENDL; protected:virtual void func () {cout<< "What's a fuck day it's" <<endl;}};
T.h
#pragma once#include "Son.h" class T:p ublic son{public:t (void) {}~t (void) {}void xy () {Base *b = new Son (); B->func ();}};
Main.cpp
#include "testInline.h" #include "Son.h" #include "T.h" void Main () {base* PB; son* PS = new Son ();p B = Ps;pb->fun (); T tst;tst.xy ();}
Results:
This is a son function
What's a fuck day it's
Changes in access permissions for virtual functions in C + +