When compiling this code I get the following error:
In function 'int main()': Line 11: error: invalid initialization of non-const reference of type 'Main&' from a temporary of type 'Main'
template <class T>
struct Main
{
static Main tempFunction(){
return Main();
}
};
int main()
{
Main<int> &mainReference = Main<int>::tempFunction(); // <- line 11
}
I don't understand why? Can anyone explain.