isInstruction()我的代码(不是我的)中有一个函数,用于设置和获取成员没有问题.现在我为了类似的目的添加了我自己的功能state().像这样:
struct foo {
bool & isInstruction() {
return isInst; // no problem
}
int & state() {
return state; //ERROR
}
private:
bool isInst;
int state;
};
Run Code Online (Sandbox Code Playgroud)
我对第一个函数没有问题.但是对于第二个,我得到了
error: invalid initialization of reference of type ‘int&’ from expression of type
‘<unresolved overloaded function type>’
Run Code Online (Sandbox Code Playgroud)
那么问题是这两个函数之间的区别是什么.我错过了什么吗?
| 归档时间: |
|
| 查看次数: |
1634 次 |
| 最近记录: |