红联Linux门户
Linux帮助

有关类的引用的问题

发布时间:2012-06-01 17:07:01来源:红联作者:zhenghaojie
#include
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< return 0;
}
这个程序在终端中用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’
请问这是什么原因呢?本人是新手,求各位大虾帮帮忙。感谢。
文章评论

共有 2 条评论

  1. wonderful5115 于 2012-06-02 11:18:27发表:

    貌似C语言

  2. lfgoxwqu 于 2012-06-01 21:19:31发表:

    不懂,帮顶下