Do you know the rules for ease of access when virtual functions are declared under 3 different access specifiers per C++(public, private, protected) What's the significance of every? Any simple code good examples to describe the idea is going to be highly helpful.

Access specifiers apply in the same manner because they would holiday to a title throughout title research. The truth that the function is virtual is not important whatsoever.

There's a typical mistake which can occur regarding virtual functions.

If title research determines a viable function to become a virtual function, the access specifier from the virtual function is checked within the scope from the static kind of the item saying used to title the function. At run time, the particular function to become known as might be defined within the derived class having a different access specifier. The reason being 'access specifiers' really are a compile time phenomonon.

// Brain compiled code ahead
struct A{
   virtual void f() {}
   virtual void g() {}
   virtual void h() {}

struct B : A{
   virtual void f() {}           // Allowed, but not a good habit I guess!

B b;
A &ra = b;

ra.f();    // name lookup of 'f' is done in 'A' and found to be public. Compilation 
           // succeeds and the call is dynamically bound
           // At run time the actual function to be called is 'B::f' which could be private, protected etc but that does not matter

Virtual functions are similar to regular functions (exception of pure virtuals) when they're utilized in the bottom class.

To summarise from the top my mind:

public functions could be utilized by anybody. private functions could be utilized simply be the course and it is buddies protected functions are just like private ones, only they may be utilized by derived classes.

Public may be the interface, andOrguarded functions would be the internals. Also observe that all of the local variables (based on encapsulism) ought to be protected/private.

Now, if this involves derived classes, you derive a category such as this:

class A : [public | protected | private] B

Now, the general publicOrpersonalOrguarded qualifier infront of B states minimal limited security level to inherit in the base class. This isn't a "filter" for that techniques and native variables meaning that some aren't inherited, it simply changes their security level towards the one specified if they're less restricted (more public).

So class A : public B will leave the inherited base people because they are while, class A : private B can change all of them to personal people.

Hope this will make sense for you and solutions your question. Otherwise, let me know!