← Back to Inheritance
Question 142
Override With Base Call and Extra Logic
Override With Base Call and Extra Logic
You are given a base class Logger with a virtual functionlog()that prints a timestamp message. Create a derived class FileLogger that: - Publicly inherits from Logger - Has a private string member: filename - Has a constructor taking a string filename - Overrideslog()to: 1. First callLogger::log()(to print the timestamp) 2. Then print "Saving to: [filename]" This pattern is common in real software: the derived class extends (not replaces) the base behavior. Do NOT include a main function. Your code will be tested automatically.
Expected Output:
[LOG] Timestamp recorded Saving to: output.txt
= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
ClassesInheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.