1

Header file:

#include <iostream>

using namespace std;

template <class A_Type> class Queue
{
    public:
        Queue(int = 10);
        Queue(const Queue<A_Type>&);
        ~Queue();
        Queue& operator=(const Queue&);
        bool enqueue(A_Type);
        bool dequeue(A_Type&);
        bool empty() const;
        bool full() const;
        bool clear();
        A_Type * getData();
        bool operator==(const Queue&) const;
        friend ostream& operator<<(ostream&, const Queue<A_Type>&);
    private:
        int max;
        int front;
        int rear;
        A_Type *data;
};

My attempt at declaring the method in Queue.cpp (The error shows up on the first line):

Queue<class A_Type>::Queue(const Queue<A_Type> &q)
{
    front = q.front;
    rear = q.rear;
    max = q.max;
    data = new A_Type[max];
    data = q.data;
}

Eclipse is throwing the error:

forward declaration of 'class A_Type'

And I'm not really sure what that means nor how to fix it. Any advice or help would be greatly appreciated.

Thank you very much in advance.

Chase
  • 13
  • 3

1 Answers1

1

Your syntax is wrong for a template method definition outside of the class declaration.

template <class A_Type>
Queue<A_Type>::Queue(const Queue<A_Type> &q)

That will take care of the error you are getting now. You may find that you have a problem, though with trying to define template methods separately in a CPP file. See Why can templates only be implemented in the header file?

Community
  • 1
  • 1
Jay Miller
  • 2,184
  • 12
  • 11