0

Here is my H file.

#include <vector>

#include "basequeue.h"

namespace advanced {

template<class T>
class AdvancedQueue {
 public:
  virtual ~AdvancedQueue();

  void GetInfo(vector<T>* events);

  void Push(const T& event);
  bool Pop(T* event);
  bool Wait(T* event);

 private:
  BaseQueue<T> queue_;
};

}

And I have implementations of these in my corresponding cpp file. When I use it, I have linking problems like so....

function advanced::Service::Handler(BaseHandler*): error: undefined reference to 'advanced::AdvancedQueue<advanced::Dashboard>::Pop(advanced::Dashboard*)'

Is there a way to specify that I will be using the "Dashboard" class? Do I have to do that separately?

Narabhut
  • 839
  • 4
  • 13
  • 30

1 Answers1

0

Is there a way to specify that I will be using the "Dashboard" class? Do I have to do that separately?

With templates, you only specify your use of Dashboard implicitly, by just using it in your source.

To satisfy that link error, replace

bool Pop(T* event);

with

bool Pop(T* event) { return true; }    //  Obviously, flesh this out as you wish.

While it is possible to provide source for specific templated cases, I discourage that. It seems to defeat the value of having a template in the first place, and when used, but not needed, it suggests the developer did not have a clear understanding of the use of templates.

donjuedo
  • 2,475
  • 18
  • 28