我有以下 foo 类的成员。
foo &foo::bar()
{
return this;
}
但我收到编译器错误。我做错了什么蠢事?
编译器错误 (gcc):错误:从 'foo* const' 类型的临时对象初始化 'foo&' 类型的非常量引用无效
最佳答案
this
是一个指针。所以应该是 return *this;
关于c++ - 从类返回引用到 this,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2621650/