所以即時通訊新的C++和它的一些破壞我的心靈。所以我需要幫助。我試圖在vector<Objects>
中搜索String object
並查看它們是否相等。在尋找和我決定使用C++中,它不斷給我的錯誤11個蘭巴表達式:比較字符串對象相當於向量中的元素
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;
}
}
我做錯了什麼。請幫我解決這個問題。會很快哭泣。預先感謝您
checkIfUserExists沒有什麼錯,除了在lambda中忘記調用c1.getEmail()。 – user1438832
我的天啊。不能相信我沒看到 – Destructor2017
一直在看着那幾小時現在:( – Destructor2017