2012-08-28 6 views
0

boost::bind의 호출에 사용되는 특정 함수 포인터 유형을 정의하지 않고 오버로드 된 함수 (static_cast 호출)와 관련된 문제를 해결하려고합니다. std::string::compare에 모호성을 해결하기 위해 typedef를 명시 적으로 정의하고 있습니다.std :: string에 대한 함수 포인터의 typedef가 작동하지 않습니다.

이 함수를 작성하면 오류가 발생합니다.

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

이 typedef의 문제점을 알고 계십니까?

답변

4

나는 이것을 원한다고 생각합니다.

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

예.

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"; 
    std::cout << (s.*resolver)("hello") << std::endl; 
} 
그리고 예를

#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

+0

안녕 영원히 바인드와. 고마워요 (일부 지연) 괜찮아요 일을 많이하고 나는 실종에 대해 깨닫지 못했 : :. –

관련 문제