Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need it in C++ Chapter 15 Inheritance, polymorphism, and Object-Oriented design

ID: 3710244 • Letter: N

Question

Need it in C++

Chapter 15 Inheritance, polymorphism, and Object-Oriented design 2.P.822, Problem 8 (20 pts) 8. A client is supplied with the following declaration for a base class and a derived class class BaseClass public: void PrintFields ) const; class DerivedClass Baseclass public: void NewFunction : Derivedclass (int StartValue); The client writes the following code to call the constructor for an object of type Derivedclass, and then prints the fields in the newly created object. DerivedClass anobject (10); anobject.PrintFields O The compiler reports an error for the second statement. What's wrong? How would you fix this problem?

Explanation / Answer

Error cause - By default, inheritance in c++ is private. So, any data member or method in BaseClass either public or protected will be private to the derived class.

So, we have to explicitily define public before the BaseClass while inheriting it

Like this-

class DerivedClass : public BaseClass{

};

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote