я работаю на очереди в C++ и у меня возникают некоторые проблемы с странными ошибками компиляции:ошибка: ... не была объявлена в этой области
Queue.h:37:49: error: expected "," or "..." before "<" token
Queue.h: In copy constructor "Queue::Queue(Queue&)":
Queue.h:39:11: error: "other" was not declared in this scope
Queue.h: At global scope:
Queue.h:42:72: error: expected "," or "..." before "<" token
Queue.h: In member function "Queue& Queue::operator=(const Queue&)":
Queue.h:44:11: error: "other" was not declared in this scope
Может кто-нибудь помочь?
#if !defined QUEUE_SIZE
#define QUEUE_SIZE 30
#endif
template <class TYPE> class Queue
{
private:
TYPE *array;
public:
Queue(Queue& other);
Queue();
~Queue();
Queue& operator=(const Queue& other);
TYPE pushAndPop(TYPE x);
};
template <class TYPE> Queue<TYPE>::Queue()
{
array=new TYPE[QUEUE_SIZE];
}
template <class TYPE> Queue<TYPE>::~Queue()
{
delete [] array;
}
template <class TYPE> TYPE Queue<TYPE>::pushAndPop(TYPE other)
{
TYPE item = array[0];
for(int x = 0; x<QUEUE_SIZE-1; x++){
array[x]= array[x+1];
}
array[QUEUE_SIZE-1] = other;
return item;
}
template <class TYPE> Queue<TYPE>:: Queue(Queue&<TYPE> other)
{
array = other.array;
}
template <class TYPE> Queue<TYPE>& Queue<TYPE>:: operator=(const Queue&<TYPE> other)
{
array = other->array;
}
'Queue &' -> 'Queue &' или просто оставить из '' . Вы должны взять 'const &' в copy-ctor, если вам не нужно использовать неконстантный '&'. Также возникает проблема с распределением памяти при использовании копии ctor (один и тот же «массив» будет удален несколько раз). –
dyp