C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

C++

Your Queue class is up and working in a customer service company. The company opens up a new branch and asks you to make another version of the Queue for them. The only difference is the way the Queue is displayed: each number on a new line. You decide to create a new class called Queue2, which is derived from the Queue class and overrides the print() method, outputting each element of the queue on a new line.

20th Nov 2021, 5:19 PM
Mando
Mando - avatar
7 Answers
+ 1
For some reason it says excepeted primary experasion before ]
20th Nov 2021, 5:26 PM
Mando
Mando - avatar
+ 2
class queue2:public Queue{ void print(){ if (size==0){ cout << "Queue is empty" << endl; return; } for (int i=0; i<size; i++){ cout << Queue[i] << endl; } } };
20th Nov 2021, 5:25 PM
Mando
Mando - avatar
+ 1
You must use the same capitalization as the declared instance variable. Correct Queue[i] with queue[i].
20th Nov 2021, 6:51 PM
Brian
Brian - avatar
+ 1
Brian thanks, but now it syas print() is not privite
21st Nov 2021, 11:54 AM
Mando
Mando - avatar
+ 1
The scope of your overriding method needs to match the original method. By default your method is private. Add a keyword to declare your print() is public.
21st Nov 2021, 3:55 PM
Brian
Brian - avatar
+ 1
public : void print(){ .. }
21st Nov 2021, 4:00 PM
Jayakrishna 🇮🇳
0
Looks like there Queue is declared as class name which you inheriting but then what is Queue[i] refers to ?
20th Nov 2021, 6:07 PM
Jayakrishna 🇮🇳