← Back to Question List
C++ Quiz #38
Method Hiding in Derived Class
This code fails to compile on the marked lines. What is the issue?
📄 Code
1#include <iostream>2using namespace std;34class Printer {5public:6 void print(int x) {7 cout << "int: " << x << endl;8 }9 void print(string s) {10 cout << "string: " << s << endl;11 }12};1314class FancyPrinter : public Printer {15public:16 void print(double d) {17 cout << "double: " << d << endl;18 }19};2021int main() {22 FancyPrinter fp;23 fp.print(3.14); // OK24 fp.print(42); // ERROR25 fp.print("hello"); // ERROR26 return 0;27}