を介してスタンドアロン関数にラップされたメンバー関数を渡そうとしていboost::bind
ます。以下は縮小サンプルです。
// Foo.h
typedef const std::pair<double, double> (*DoubleGetter)(const std::string &);
class Foo : private boost::noncopyable {
public:
explicit Foo(const std::string &s, DoubleGetter dg);
};
// Bar.h
struct Bar {
const std::pair<double, double> getDoubles(const std::string &s);
};
// main.cpp
boost::shared_ptr<Bar> bar(new Bar());
std::string s = "test";
Foo foo(s, boost::bind(&Bar::getDoubles, *(bar.get()), _1));
ただし、次のテキストでコンパイラ エラーが発生しました。
/home/Loom/src/main.cpp:130: error: no matching function for call to
‘Foo::Foo
( std::basic_string<char, std::char_traits<char>, std::allocator<char> >
, boost::_bi::bind_t
< const std::pair<double, double>
, boost::_mfi::mf1
< const std::pair<double, double>
, Bar
, const std::string&
>
, boost::_bi::list2
< boost::_bi::value<Bar>
, boost::arg<1>
>
>
)’
/home/Loom/src/Foo.h:32: note: candidates are:
Foo::Foo(const std::string&, const std::pair<double, double> (*)(const std::string&))
/home/Loom/src/Foo.h:26: note:
Foo::Foo(const Foo&)
コードの問題とそのような問題を回避する方法は?