using namespace std;
class A
{
public:
A(int i){x=i;}
int get(){return x;}
private:
int x;
};
A func()
{
A a(23);
return a;
}
int main()
{
A &r=func();
cout<
}
这个程序在终端中用G++调试的时候老是出现:
9.16.cpp: In function ‘int main()’:
9.16.cpp:18: error: invalid initialization of non-const reference of type ‘A&’ from a temporary of type ‘A’
请问这是什么原因呢?本人是新手,求各位大虾帮帮忙。感谢。
wonderful5115 于 2012-06-02 11:18:27发表:
貌似C语言
lfgoxwqu 于 2012-06-01 21:19:31发表:
不懂,帮顶下