使用 std::map::at 时对 std::map 的调用不匹配

问题描述 投票:0回答:0

我遇到了 std::map 函数的问题。

简而言之,我的代码由一个模板基类组成,在该类中,我有一个如下所示的结构:

template <class DERIVED>
class base 
{
public: 
struct association
{
    bool accept_country{false};
    int(DERIVED::*fp)(const std::string country);
}

// The class have a lot of methods where I get the map, do some logic around and one of them I call the function call_visa in this way 
int another_method(blabla)
{
  ret_fp = base<DERIVED>::call_visa(func_map, name, "Brazil");
}

int call_visa(std::map<std::string, association> *func_map, const std::string& name, std::string country))
{
  return func_map->at(name)(country);
}

[...]

然后我有一个派生类,如下所示:

class derived : public base<derived>                      
{ 
private:
  std::map<std::string, association> func_map; 
  int visa_renata(std::string country)
  {
    // do_something
    return 0;
  }

public:
  derived()
  {
    cmd_association tmpinit[] = { 
    {true, &derived::visa_renata}};
    func_map["Renata"] = tmpinit[0];
  }
  inline std::map<std::string, association>& getMap() { return func_map;}

当我编译代码时,在函数 call_visa 的返回中出现错误“不匹配对 std::map 的调用”。

有谁知道我应该怎么做才能摆脱这个错误?

string function-pointers stdmap
© www.soinside.com 2019 - 2024. All rights reserved.