类型引用的初始化无效
invalid initialization of reference of type
在我的代码(不是我的)中有一个函数isInstruction()
,用于设置和获取成员,没有问题。现在我为类似的目的添加了我自己的函数state()
。这样的:
struct foo {
bool & isInstruction() {
return isInst; // no problem
}
int & state() {
return state; //ERROR
}
private:
bool isInst;
int state;
};
我对第一个函数没有问题。但是对于第二个,我得到
error: invalid initialization of reference of type ‘int&’ from expression of type
‘<unresolved overloaded function type>’
那么问题是这两个函数有什么不同。我错过什么了吗?
不同之处在于两个实体(成员变量和成员函数)共享相同的名称state
,这就是导致问题的原因。
尝试重命名其中一个
相关文章:
- C++-模板嵌套类的引用初始化无效
- 从 BubbleSort* 类型的右值初始化 'AssortedSorter&' 类型的非常量引用无效"
- wxWidgets 拖放文件事件处理程序初始化问题(无效static_cast)
- 为什么我总是收到此错误:从类型为"农场动物"的右值初始化类型的非常量引用无效|
- 对全局变量的非常量引用的初始化无效
- 对类型为 std::_Bit_rerefence& 的非常量引用的初始化无效
- 模板流运算符重载错误:引用初始化无效,与basic_istream和basic_ifstream之间的差异有关
- 成本字符*类型的非常量引用的无效初始化,并且来自常量字符*类型的临时引用
- C++ 解决方法:"从类型"B*"的表达式初始化类型"C*&"的引用无效"
- 使用无效指针初始化指针声明符的行为是否未定义?
- 'inherit class'中类型 'template class' 引用的初始化无效
- 无效初始化类型的 BinaryNode *& 的非常量引用
- 来自类型为std::basic_string::const_iterator的非常量引用的无效初始化,并且<char>来自类型std::basic_string<char>::
- 引用的无效初始化是什么意思
- 从类型为"<大括号括起来的初始值设定项列表>"的类型非常量引用的无效初始化
- 非常量引用类型的无效初始化中出错.在Linux操作系统中使用c++代码.GCC编译器
- 模板函数c++类型的非const引用的无效初始化
- <Object> 什么是无效初始化(处理<Object>导出)
- 对引用使用多态性.非const引用的无效初始化
- Mat::at - error:类型的非const引用的无效初始化的包装器