0

の呼び出しで使用される特定の関数ポインタタイプを定義して、boost::bind(を呼び出すことによって)認識されないオーバーロードされた関数に関連する問題を解決しようとしていますstatic_cast。のあいまいさを解決するために、そのtypedefを明示的に定義していますstd::string::compare

この関数を書くとエラーが発生しました。

   typedef int(std::string* resolve_type)(const char*)const;

このtypedefの何が問題になっているのか知っていますか?

4

1 に答える 1

4

これが欲しいと思います。

typedef int(std::string::*resolve_type)(const char*) const;

例。

#include <iostream>
#include <functional>

typedef int(std::string::*resolve_type)(const char*)const;

int main()
{
   resolve_type resolver = &std::string::compare;
   std::string s = "hello";
   std::cout << (s.*resolver)("hello") << std::endl;
}

http://liveworkspace.org/code/4971076ed8ee19f2fdcabfc04f4883f8

そしてバインドの例

#include <iostream>
#include <functional>

typedef int(std::string::*resolve_type)(const char*)const;

int main()
{
   resolve_type resolver = &std::string::compare;
   std::string s = "hello";
   auto f = std::bind(resolver, s, std::placeholders::_1);
   std::cout << f("hello") << std::endl;
}

http://liveworkspace.org/code/ff1168db42ff5b45042a0675d59769c0

于 2012-08-28T09:58:47.753 に答える