โ 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 function log() 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 - Overrides log() to: 1. First call Logger::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
Expected Output:
[LOG] Timestamp recorded Saving to: output.txt
Topics:
ClassesInheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท 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.