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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 14:38:01  来源:igfitidea点击:

non-standard syntax; use '&' to create a pointer to member

c++

提问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 autoor size_tinstead of int. comparing signed and unsigned values can lead to errors.

此外,在C ++的世界里,我会建议对写作for (int...,喜欢autosize_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 rescanTargetor rescan_target, but not rescan_Target(which I believe is the translation for "rechercher_Trajet"?).

我将函数命名为rescanTargetor rescan_target,但不是rescan_Target(我认为这是“rechercher_Trajet”的翻译?)。