Difficulty: Easy
Correct Answer: Incorrect statement — the derived object can call func() if it is accessible via inheritance.
Explanation:
Introduction / Context: The claim suggests a derived object cannot access a base member unless the derived redeclares it. In C++, members of the base are part of the derived object as long as they are not hidden and remain accessible under the chosen inheritance mode (public/protected/private) and access level (public/protected).
Given Data / Assumptions:
func() that is accessible to Derived (e.g., public).func().Concept / Approach: With public inheritance, public base members remain public in the derived interface. Therefore, calls like Derived d; d.func(); are perfectly valid. Virtual is not required to call the function; virtual only affects which implementation runs when calling through a base interface and enabling overriding. If Derived declared another overload with the same name, name hiding could affect lookup, but in the scenario stated, no such overload exists.
Step-by-Step Solution:
Base::func() exists and is accessible. Derived does not declare its own func(). An expression of type Derived calls func() → Base::func() executes.Verification / Alternative check: Change inheritance to private: public members of Base become private within Derived and may not be callable from outside via a Derived object, but still callable inside Derived’s own member functions — showing access control matters, not the existence of an override.
Why Other Options Are Wrong:
Common Pitfalls: Confusing overriding with availability; and conflating access specifiers with the need to redeclare symbols in the derived class.
Final Answer: Incorrect statement — the derived object can call func() if it is accessible via inheritance.
Discussion & Comments