0

This is a follow up of this question (I will post the necessary class definitions at the end so that to understand it)

This time I have

Class1<Class2> & anObject= Class1Singleton::GetInstance();

I corrected the previous error, so that now GetInstance() that returns an object of type Class1 (not a singleton!) is assigned to the correct type.

I try to build this and it compiles! However this time I got a linker error

undefined reference to Singleton<Class1<Class2>>::GetInstance()
collerc2: error: ld returned 1 exit status

At first I thought it was not a singleton anymore, but actually Class1Singleton is a singleton! Why is the linker not able to reference its function?


The classes are:

template <class T>
class Singleton {
public:
    static T& GetInstance()
    {
        static T instance;
        return instance;
    }

private:
    Singleton() {}
    ~Singleton() = default;
}

and

class Class2;

template <class T>
class Class1{
  void sayHi();
};

using Class1Singleton= Singleton<Class1<Class2>>;
KansaiRobot
  • 7,564
  • 11
  • 71
  • 150

0 Answers0