-2

I'm trying to implement a generic Queue class. The Template class looks like it: Queue.h

template <class T>
class Queue {
public:
  Queue() {}
 ~Queue() {} 

...

  void enqueue( const T& e );
  T dequeue( void );

  int Size( void ) const { return s1.size() + s2.size();}    

private:
    std::stack<T> s1;
    std::stack<T> s2;
};

#include "Queue.cpp"

And the implementation of it looks like it:
Queue.cpp:

#include "Queue.h"

template <class T>
void Queue<T>::enqueue( const T& e )
{
//...
}

template <class T>
T Queue<T>::dequeue ()
{
//...
}

my Problem is, i can't call some function of this class whtich I've implemented in the file Queue.cpp.

main.cpp:

int main() {
Queue<int> myQueue;

const int a = 1;
 myQueue.enqueue(a);

 myQueue.Size();

return 0;
}

i become always the follwing erro: undefined reference to Queue::enqueue(int const&)

[Error] ld returned 1 exit status

Makefile.winrecipe for target 'MYQueue.exe' failed

user3605330
  • 41
  • 1
  • 4
  • I includee accordings to this post, the implementation file at the end of the header. And now I become the errors: [Error] redefinition of 'Queue::Queue(const Queue&)' etc... – user3605330 May 08 '14 at 20:15

1 Answers1

1

Place the whole template definition including its member functions in one header file.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335