Add() is only private in derived but the static type you have is base thus the access restrictions of base apply In general you can't even know at compile time what the dynamic type of a pointer to base will be, it could e.g. Change based on user input This is per C++03 §11.6 : The access rules (clause 11) for a virtual function are determined by its declaration and are not affected by the rules for a function that later overrides it ... Access is checked at the call point using the type of the expression used to denote the object for which the member function is called .... The access of the member function in the class in which it was defined ... is in general not known.
Add() is only private in derived, but the static type you have is base* - thus the access restrictions of base apply. In general you can't even know at compile time what the dynamic type of a pointer to base will be, it could e.g. Change based on user input. This is per C++03 §11.6: The access rules (clause 11) for a virtual function are determined by its declaration and are not affected by the rules for a function that later overrides it.
... Access is checked at the call point using the type of the expression used to denote the object for which the member function is called .... The access of the member function in the class in which it was defined ... is in general not known.
1 - Thanks for the clarifying comment on my answer. – Kyle Rozendo Aug 31 '10 at 16:17.
To add a little to Georg's answer: Remember that the compiler has no control over and cannot guarantee anything about derived classes. For example, I could ship my type in a library and derive from it in an entirely new program. How is the library compiler supposed to know that derived might have a different access specifier?
The derived type didn't exist when the library was compiled. In order to support this, the compiler would have to know access specifiers at runtime and throw an exception if you attempted to access a private member.
Access modifiers, such as public, private and protected are only enforced during compilation. When you call the function through a pointer to the base class, the compiler doesn't know that the pointer points to an instance of the derived class. According to the rules the compiler can infer from this expression, this call is valid.It is usually a semantic error to reduce the visibility of a member in a derived class.
Modern programming languages such as Java and C# refuse to compile such code, because a member that is visible in the base class is always accessible in the derived class through a base pointer.
1 Best answer. – Tomalak Geret'kal May 11 at 9:25.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.