所以我对c ++很陌生,而且它会破坏我的思想。所以我需要帮助。我试图在String object
中搜索vector<Objects>
并查看它们是否相等。正在搜索,我决定使用c ++ 11 lamba表达式,它一直给我错误:
Severity Code Description Project File Line Suppression State
Error C3867 'User::getEmail': non-standard syntax; use '&' to create a pointer to member EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110
Severity Code Description Project File Line Suppression State
Error C2678 binary '==': no operator found which takes a left-hand operand of type 'overloaded-function' (or there is no acceptable conversion) EmailServerClientApp c:\users\user\desktop\emailserverclientapp\emailserverclientapp\guinterface.cpp 110
我创建了一个重载运算符(或者至少我对c ++的了解,我认为我做过)。看不出这个有什么不对。
这是我的用户类:
private:
string userName;
string password;
string email;
public:
User();
User(string name, string pass, string e);
void setUserName(string name);
void setPassword(string pass);
void setEmail(string e);
bool numberInString(const std::string& s);
void print()const;
User &operator=(User other)
{
std::cout << "copy assignment of Email\n";
std::swap(userName, other.userName);
std::swap(password, other.password);
std::swap(email, other.email);
return *this;
}
friend bool operator ==(const User &c1, const string &e);
string getUserName()const;
string getPassword()const;
string getEmail()const;
~User();
};
创建运算符以检查是否等于:
bool operator==(const User & c1, const string& e )
{
return (c1.email == e);
}
这个方法在这里我试图在向量中找到实际的电子邮件:
bool checkIfUserExists(vector<User> v,string email, string password) {/* using c++11 lamba expression to find an
element in vector matching my string object
*/
vector<User>::iterator it = std::find_if(v.begin(), v.end(), [&email](const User&c1) {return c1.getEmail == email; });
if (it != v.end())
{
return true;
}
else {
return false;
}
}
我在做错了什么。我需要帮助。很快就会哭。提前谢谢
答案 0 :(得分:1)
{return c1.getEmail == email;}
getEmail()
是一个类方法,而不是类成员。正确的语法应该是:
{return c1.getEmail() == email;}