【问题标题】:Comparing values in a stl list<> that is populated with a class比较填充有类的 stl list<> 中的值
【发布时间】:2014-11-22 18:57:29
【问题描述】:

我一直在玩弄我的代码,试图改进它,但我坚持了这部分。

我有以下标题

Funcionario.h

class Funcionario
{
private:
std::string Userid;
std::string Nome;
std::string Sobrenome;
std::string Email;
std::string Pass;

public:
Funcionario(std::string Userid, std::string Nome, std::string Sobrenome, std::string Email, std::string Pass);
~Funcionario(void);

string GetUserID()  { return Userid;    }
string GetName()    { return Nome;  }
string GetSName()   { return Sobrenome; }
string GetEmail()   {return Email;  }
string GetPass()    { return Pass;  } 
};

这是我的表格,注意不是整个表格,只是重要的部分;

#include <list>
#include <algorithm>
#include "Funcionario.h"



Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
LF = new list<Funcionario>();
}

//Button click    
list<Funcionario>::iterator it1 = find(LF->begin(), LF->end(), ID); //*Searches for ID

当我尝试运行它时,它说没有合适的转换器来提供 Funcionario。 任何帮助都将不胜感激,并在此先感谢您。

【问题讨论】:

    标签: list class stl c++-cli


    【解决方案1】:
    list<Funcionario>::iterator it1 = find_if(LF->begin(), LF->end(),
      [&ID](const Funcionario& f) { return f.GetUserId() == ID; } );
    

    【讨论】:

    • 非常感谢您回复 Igor,但它在 [&ID] 中出现了一点错误。错误:“托管类的成员函数中不允许使用本地 lambda”知道这是什么吗?
    • 这意味着您使用的不是 C++,而是一种不同的、关系较远的语言,称为 C++/CLI。除了它的存在之外,我对它并不熟悉。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-07
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    相关资源
    最近更新 更多