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.
7 Answers
+ 1
For some reason it says excepeted primary experasion before ]
+ 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;
}
}
};
+ 1
You must use the same capitalization as the declared instance variable.
Correct Queue[i] with queue[i].
+ 1
Brian thanks, but now it syas print() is not privite
+ 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.
+ 1
public :
void print(){
..
}
0
Looks like there Queue is declared as class name which you inheriting but then what is Queue[i] refers to ?