When compiling this code I get the following error:
In function \'int main()\': Line 11: error: invalid initialization of non-const reference of typ
In C++ temporaries cannot be bound to non-constant references.
Main<int> &mainReference = Main<int>::tempFunction();
Here you are trying to assign the result of an rvalue expression to a non-constant reference mainReference which is invalid.
mainReference
Try making it const
const