相关疑难解决方法(0)

从类返回引用

我有类foo的以下成员.

foo &foo::bar()
{
   return this;
}
Run Code Online (Sandbox Code Playgroud)

但我收到编译器错误.我做错了什么蠢事?

编译器错误(gcc):错误:从类型为'foo*const'的临时类中初始化'foo&'类型的非const引用

c++ return reference this

13
推荐指数
2
解决办法
6049
查看次数

标签 统计

c++ ×1

reference ×1

return ×1

this ×1