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'
Here's my code:
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?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…