Std::set构造函数第二个参数错误



Codeblocks在这一行引发错误:

set<string,cmpi> m;

其中cmpi函数为:

int cmpi(string one , string two )
{
    one = toLowerCase(one); 
    two = toLowerCase(two);
    if(two == one) 
        return 0;
    else 
    if (one < two ) 
        return -1;
    else 
        return 1;
}

它说(错误):

type/value mismatch at argument 2 in template parameter list for 'template<class _Key, class _Compare, class _Alloc> class std::set'

是否有我的cmpi函数的返回值或其他东西?

type/value mismatch

std::set期望类型,而不是函数指针():

int cmpi(string one, string two);
typedef int cmpi_t(string one, string two); // the type of cmpi
std::set<string, cmpi_t*> m (&cmpi);

第二个参数必须是一个类型。您可以像这样为函数创建一个类型:

struct CmpI {
  bool operator()(const string &a,const string &b) { return cmpi(a,b)<0; }
};