比较字符串对象等于向量中的元素
Compare string object equals to element in vector
所以我对C 的新手有些破坏。因此,我需要帮助。IM尝试在vector<Objects>
中搜索String object
,看看它们是否相等。正在搜索,我决定使用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:usersuserdesktopemailserverclientappemailserverclientappguinterface.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:usersuserdesktopemailserverclientappemailserverclientappguinterface.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 Emailn";
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;
}
}
我在做什么错。请我需要帮助。很快就会哭泣。预先感谢
{return c1.getEmail == email;}
getEmail()
是一种类方法,而不是类成员。正确的语法应为:
{return c1.getEmail() == email;}
相关文章:
- 向量元素的引用地址与它所指向的向量元素的地址不同.为什么
- 在 C++ 中输出枚举类类型的向量元素
- 用向量的向量元素初始化向量的空向量
- 为什么不允许使用可变长度数组作为向量元素?
- 在函数中传递向量元素
- 使用 Rcpp 加速替换迭代算法中的列表和向量元素是否合法?
- 返回向量元素的 l 值的正确方法是什么?
- 当向量增长时,指向向量元素的C++指针是否无效
- 如何在C++中从一个向量元素减去std::unorderede_map向量元素并更新它
- C++:向量元素赋值导致访问冲突
- 将向量元素与字符串元素进行比较,而不初始化向量
- 从2D矢量中找出最小尺寸的向量元素的更好方法
- 当我尝试将一个向量元素的值分配给另一个向量元素时,为什么我的应用程序会崩溃
- 使用递归C++向量元素的总和
- 如何查找为数组中的最低值编制索引的向量元素
- 限制指针访问STL ::向量元素
- 访问索引指向向量元素时的seg故障 - 做错了什么
- 如何使用指针访问向量元素的各个元素
- 向量元素数据损坏了Find()操作
- 将字符值分配给向量元素.C