A client is supplied with the following declaration for a base class and a deriv
ID: 3529188 • Letter: A
Question
A client is supplied with the following declaration for a base class and a derived class: class BaseClass { public : . . . }; 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 print the fields in the newly created object. DerivedClass anObject (10); anObject.PrintFields(); The compiler reports an error for the second statement. What wrong? How would you fix this problem?Explanation / Answer
Error 1: You have to define PrintFields() method in derived class. Solution: class DerivedClass : BaseClass { public : void NewFunction(); DerivedClass (int StartValue); void PrintFields(); }; void DerivedClass :: PrintFields() { } Error 2: You defined the parameterized constructor, but you didn't defined it. So you have to define it. Solution: class DerivedClass : BaseClass { public : void NewFunction(); DerivedClass (int StartValue); void PrintFields(); }; DerivedClass :: DerivedClass (int StartValue) { }
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.