"非标准语法;使用“&”创建指向“成员”的指针Visual Studio 2015中的错误 [英] "non-standard syntax; use '&' to create a pointer to member" error in Visual Studio 2015

查看:66
本文介绍了"非标准语法;使用“&”创建指向“成员”的指针Visual Studio 2015中的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有此功能:

std::string Room::getUsersAsString(std::vector<User*> usersList, User * excludeUser)
{
    std::string usersNames = " ";

    for (int i = 0; i < usersList.size(); i++) {
        if (usersList[i]->getUsername() != excludeUser->getUsername) {
            usersNames.append(usersList[i]->getUsername);
            usersNames.append(" ");
        }
    }

    return usersNames;
}

每当我尝试运行程序时,都会出现以下错误:

Whenever I try to run the program, I get the following error:


非标准语法;使用'&'创建指向成员的指针

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

我该如何解决?

推荐答案

如果使用

if (usersList[i]->getUsername() != excludeUser->getUsername)

而不是

if (usersList[i]->getUsername() != excludeUser->getUsername())

您的编译器会认为您想使用函数指针而不是方法本身,并且如果您想使用函数指针,则仍然必须获取地址(使用&)。

your compiler will think you want to use a function pointer instead of the method itself, and if you would have wanted to use a function pointer, you would still have to get the address of it (using &).

因此请确保在函数调用后不要忘记()!!

So make sure you don't forget your () after a function call!

这篇关于&quot;非标准语法;使用“&amp;”创建指向“成员”的指针Visual Studio 2015中的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆