2016-10-24 16 views
-1

C++ 유형 ID는 오버로드

class A 
{ 
public: 
    void operator()(int); 
    void operator()(const std::string&) {} 
}; 

std::cout << typeid(&A::operator()).name() << std::endl; 

그것은 오류를 제공, GCC 4.8.2에서 다음 작업을 수행 할 때 :

그것은 같은 다른 클래스 멤버 연산자 작동
error: address of overloaded function with no contextual type information. 

연산자 ==. 그 구문 오류 A :: operator()에 대한 typeid() 호출에 있습니까?

편집 : 죄송합니다. 이 문제는 여러 개의 오버로드 된 operator()가있을 때 발생합니다.

+1

는 [나를 위해 일]로 보인다 (http://rextester.com/PFM1036) –

+1

는 GCC 6.2 –

+0

죄송합니다, 내 나쁜로 재현 할 수 없습니다. 질문을 수정했습니다. 오버로드 된 operator()가 여러 개 정의되어있을 때 발생합니다. – surfcode

답변

2

static_cast을 사용하면 과부하로 원하는 것을 선택할 수 있습니다.

또한 static_caststd::transform(s.begin(), s.end(), s.begin(), static_cast<int(*)(int)>(std::toupper));

예에서와 같이, 특정 유형의 함수 포인터 간 변환을 수행하여 함수의 과부하를 명확하게하기 위해 사용될 수있다

std::cout << typeid(static_cast<void(A::*)(int)>(&A::operator())).name() << std::endl; 

LIVE