0

I wrote a template class for a Singleton

singleton.cpp:

template<typename T>
class Singleton {

  protected:
    Singleton() = default;

  public:
    virtual ~Singleton() = default;
    Singleton(const Singleton<T>&) = delete;

  public:
    Singleton& operator=(const Singleton&) = delete;

  public:
    static T& GetInstance() {
      static T instance;

      return instance;
    }

}

And my logger class inherits this template

class Logger : public Singleton<Logger> {

  private:
    Logger();

  public:
    ~Logger;
}

but when i call Application::GetInstance() I get an undefined reference undefined reference to `Singleton<Application>::GetInstance()

Symlink
  • 383
  • 2
  • 12
  • 4
    Does this answer your question? [Why can templates only be implemented in the header file?](https://stackoverflow.com/questions/495021/why-can-templates-only-be-implemented-in-the-header-file) – Richard Critten Sep 28 '20 at 08:25
  • There is no `GetReference` declared in the code you showed us – Sebastian Hoffmann Sep 28 '20 at 08:31
  • Why do you have a class in `.cpp` file? You have to `include` it for `Logger` class, and you should never include a `.cpp` file. – Yksisarvinen Sep 28 '20 at 08:49

0 Answers0