当编译这个代码,我得到以下error:非const引用的无效初始化是什么意思?
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
}
我不明白为什么?谁能解释一下?
什么是错误 – Mark 2010-09-15 17:10:28
请张贴从编译器确切的错误消息。 – 2010-09-15 17:10:41
您的模板声明不依赖于参数化的类。 – 2010-09-15 17:11:34