0
Your Queue! Problem
I’m having trouble figuring out what’s wrong with my code for the Your Queue! problem. Any assistance would be greatly appreciated. My code will be posted in the next comment.
4 odpowiedzi
+ 1
The error I’m getting right now is “T does not name a type - line 31”
0
#include <iostream>
using namespace std;
int *arr;
int count;
void add(int elem) {
arr[count] = elem;
count++;
}
void get(int index) {
cout << arr[index]<<endl;
}
template <class T>
class Queue
{
//private:
//T add, get;
public:
Queue(int size) {
arr = new int[size];
count = 0;
}
T add();
T get();
};
template <class T>
T Queue <T>::add(){
}
T Queue <T>::get(){
}
int main()
{
Queue<string> q(4);
q.add("James");
q.add("Andy");
q.add("Amy");
q.get(2);
Queue <int> n(2);
n.add(42);
n.add(33);
n.get(1);
return 0;
}
0
You had to write the function body of add() and get() of the class Queue and and not create another functions doing the same.
0
#include <iostream>
using namespace std;
template<class T>
class Queue{
private:
int *arr;
int count;
public:
Queue(int size) {
arr = new int[size];
count = 0;
}
void add(int elem) {
arr[count] = elem;
count++;
}
void get(int index) {
cout << arr[index]<<endl;
}
T add();
T get();
};
template<class T>
T Queue<T>::add( ){
}
T Queue<T>::get(){
}
int main(){
Queue<string> q(4);
q.add("James");
q.add("Andy");
q.add("Amy");
q.get(2);
Queue <int> n(2);
n.add(42);
n.add(33);
n.get(1);
return 0;
}
Here is a rewrite of my code. Still getting error that says “Line 30 - T does not name a type.” Please help. Thanks!