【发布时间】:2012-04-01 12:58:46
【问题描述】:
我有以下代码,其中 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&)'的使用无效
在我调用 boost::bind 的那一行。
我在做什么才应得这个错误?
【问题讨论】:
-
尝试将您的问题减少到更小的样本。这里与
boost.locale无关。纯粹是bind。这使得诊断它们变得容易得多。 -
我通常会这样做,但老实说我不确定这是否与 Boost.Locale 的怪异有关。
标签: boost boost-bind boost-function