2012-04-01 16 views
1

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

error: invalid use of non-static member function ‘std::vector moFinder::findMo(const std::string&, const std::string&)’

:コンパイルする場合

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; 

    // ... 
} 

は、私は次のエラーを取得します。

このエラーを表示するにはどうすればよいですか?

+0

問題を小さなサンプルに減らしてください。 'boost.locale'とは何も関係ありません。それは純粋に 'バインド'です。これにより、それらをより簡単に診断することができます。 – pmr

+0

私はいつもやっていますが、Boost.Localeの奇妙さと関係があるかどうかは正直に分かりませんでした。 – Jookia

答えて

5

メンバーアドレスの前にオペレータのアドレスがありません:&moFinder::findMo。さらに、メンバ関数を関数オブジェクトにラップするには、boost::mem_fnを使用する必要があります。また、プレースホルダがありません。オールインワン:

boost::bind(boost::mem_fn(&moFinder::findMo,), boost::ref(finder), _1, _2); 
               // or &finder 
+0

ありがとう!私はboost :: mem_fnや_1、_2sを見たことがありませんでした。 – Jookia

+1

@Jookia boost.bindのドキュメントですか? http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html;) – pmr

関連する問題