2016-12-21 7 views
-2

私はC++に新しいので、私の心は少し壊れています。だから私は助けが必要ですのString objectを検索し、それらが等しいかどうかを調べようとしています。検索し、私はそれは私にエラーを与え続け++ 11のラムダ式cを使用することが決定された:私はオーバーロード演算子を作成した(あるいは、少なくともCの私の知識に私は私がやったと思う++)ベクトル内の要素と文字列オブジェクトを比較する

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 

。これで何が間違っているのか分かりません。

これは私のユーザークラスです:

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

lambdaを除いてcheckIfUserExistsに間違いはありませんが、c1.getEmail()を呼び出すことは忘れてしまいます。 – user1438832

+0

ああ私の神。私はそれを見たことがないと信じています – Destructor2017

+0

それは数時間今見ている:( – Destructor2017

答えて

1
{return c1.getEmail == email;} 

getEmail()はクラスメンバーではなくクラスメソッドです。正しい構文は次のとおりです。

{return c1.getEmail() == email;} 
+0

ああ、私の神は今屋根から飛び降りるだろうhahah – Destructor2017

+0

感謝しています: – Destructor2017

関連する問題