CJCoding With Joseph
15per day
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #38

Method Hiding in Derived Class

mediumInheritance

This code fails to compile on the marked lines. What is the issue?

📄 Code

1#include <iostream>
2using namespace std;
3 
4class 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};
13 
14class FancyPrinter : public Printer {
15public:
16 void print(double d) {
17 cout << "double: " << d << endl;
18 }
19};
20 
21int main() {
22 FancyPrinter fp;
23 fp.print(3.14); // OK
24 fp.print(42); // ERROR
25 fp.print("hello"); // ERROR
26 return 0;
27}