C++ 非标准语法;使用“&”创建指向成员的指针
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36765432/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
non-standard syntax; use '&' to create a pointer to member
提问by M.REB
I'm sure about my function , but I didn't know the meaning of this error
我确定我的函数,但我不知道这个错误的含义
"non-standard syntax; use '&' to create a pointer to member"
this is my function : recherche d'un trajets dans un vector du trajets
这是我的职能:recherche d'un trajets dans un vector du trajets
int compagnie::rechercher_Trajet(int ind)
{
for (int i = 0; i < tab_Trj.size(); i++)
{
if (tab_Trj[i]->getNum == ind)
return i;
return -1 ;
}
}
class trajets :
int getNum() { return numero; }
};
am asking for your help , thnx
我在寻求你的帮助,谢谢
回答by David Haim
well...
好...
if (tab_Trj[i]->getNum() == ind)
you forgot the ()
.
你忘记了()
。
also, in the C++ world, I would advise against writing for (int...
, prefer auto
or size_t
instead of int
. comparing signed and unsigned values can lead to errors.
此外,在C ++的世界里,我会建议对写作for (int...
,喜欢auto
或size_t
代替int
。比较有符号和无符号值可能会导致错误。
PS. it is extremly not common to name entities in your program in a language which is not english. also, you are mixing underscore-convention with lower camel case-convention.
附注。在程序中用非英语语言命名实体是非常不常见的。此外,您正在将下划线约定与较低的骆驼案例约定混合在一起。
I'd name the function either rescanTarget
or rescan_target
, but not rescan_Target
(which I believe is the translation for "rechercher_Trajet"?).
我将函数命名为rescanTarget
or rescan_target
,但不是rescan_Target
(我认为这是“rechercher_Trajet”的翻译?)。