错误 C3867 "数据库::是用户和通行证匹配":非标准语法;使用 '&' 创建指向 Membe 的指针

Error C3867 'DataBase::isUserAndPassMatch': non-standard syntax; use '&' to create a pointer to membe

本文关键字:创建 使用 Membe 指针 非标准 用户 数据库 C3867 通行证 错误 语法      更新时间:2023-10-16

我已经想了一段时间,但找不到解决方案。

当我在另一个cpp文件中写下这行代码时:

if(DataBase::isUserAndPassMatch(u->getUsername(), " ")){}

我得到错误C3867。我试图将u->getUsername()切换为空字符串("),但仍然出现相同的错误。我也试过这个:

 if(&DataBase::isUserAndPassMatch(u->getUsername(), " ")){}

isUserAndPassMatch:

bool DataBase::isUserAndPassMatch(std::string username, std::string password){}

假设您有类定义:

class DataBase {
public
   bool isUserAndPassMatch() {return true;}
};

如果你想调用isUserAndPassMatch成员函数,你必须有对象:

DataBase db;
if( db.isUserAndPassMatch() ) {
}

试试看。