I have a rather complicate singleton template starting with
template <class T>
class Singleton {
public:
static T& GetInstance(){
static T instance;
return instance;
}
private:
Singleton() {}
~Singleton() = default;
};
and then
class Class2;
template <class T>
class Class1{
void sayHi();
};
using Class1Singleton= Singleton<Class1<Class2>>;
So you can see I have a singleton of Class1 (that is also template based so I use Class2 for that).
Then in another part of the code I have
Class1Singleton & anObject= Class1Singleton::GetInstance();
When I try to build this I get this error
error: invalid initialization of reference of type
‘Class1Singleton& {aka Singleton<Class1<Class2> >&}’
from expression of type ‘Class1<Class2>’
Class1Singleton::GetInstance();
^
Why is the Singleton being ignored??