1

Boost.Local が関数コールバックを使用して mo ファイルをロードする次のコードがあります。この関数は私にとっては findMo と呼ばれ、moFinder のプライベート メンバーに追加した副作用を保持できるように、それをオブジェクトにバインドしようとしています。

class moFinder
{
  public:
    moFinder(string const& wantedFormat)
    : format(wantedFormat)
    {
      // ...
    }

    std::vector<char> findMo(std::string const& filePath, std::string const& encoding)
    {
      // ...
    }
};

std::locale createLocale(string const& name, string const& customTranslation,
  string const& path, string const& domain, string const& pathFormat)
{
  // ...

  namespace blg = boost::locale::gnu_gettext;
  blg::messages_info info;
  info.paths.push_back(path);
  info.domains.push_back(blg::messages_info::domain(domain));

  moFinder finder(pathFormat);

  blg::messages_info::callback_type callbackFunc;
  callbackFunc = boost::bind(moFinder::findMo, boost::ref(finder));

  info.callback = callbackFunc;

  // ...
}

コンパイルすると、次のエラーが発生します。

エラー: 非静的メンバ関数 'std::vector moFinder::findMo(const std::string&, const std::string&)' の無効な使用</p>

boost::bind を呼び出す行。

このエラーに値するために私は何をしていますか?

4

1 に答える 1

5

メンバーの住所の前にオペレーターの住所がありません: &moFinder::findMoboost::mem_fnさらに、メンバー関数を関数オブジェクトにラップするために使用する必要があり、プレースホルダーがありません。概して:

boost::bind(boost::mem_fn(&moFinder::findMo,), boost::ref(finder), _1, _2);
                                               // or &finder 
于 2012-04-01T13:02:01.590 に答える