2011-04-27 2 views
6

토큰 :이상한 GCC 오류 : 전에 예상되는 주요 표현 ','난 아직 GCC에 MSVC에서 마이그레이션하기 위해 노력하고있어,하지만 다음과 같은 문제에 대한 해결책 찾을 수 없습니다

template < typename A, typename B, typename C, typename D > 
class Test 
{ 
public: 
    Test (B* pObj, C fn, const D& args) : _pObj(pObj), _fn(fn), _args(args) 
    { 
    } 

    A operator()() 
    { 
     return _args.operator() < A, B, C > (_pObj, _fn); // error: expected primary-expression before ',' token 
    } 

    B* _pObj; 
    C _fn; 
    D _args; 
}; 

을 도와주세요!

답변

19

시도 return _args.template operator() < A, B, C > (_pObj, _fn);.

template 키워드가 없으면 구문 분석이 달라집니다. template을 추가로 사용하지 않으면 컴파일러는 뒤에 오는 less than 토큰 (<)이 실제로 "미만"이 아니라 템플릿 인수 목록의 시작임을 알 수 있습니다.

14.2/4

When the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.

P.S :이 Stackoverflow FAQ Entry

+1

매우 감사 읽어보세요! 템플릿 키워드에 대해 알고 있었지만 메소드 선언에 사용하는 방법을 생각해 본 적이 없습니다 ... 이제 알았습니다. 고마워요! – Ryan

+0

나도 고마워. 나는 이것에 관해 완전히 잊었다. 이것은 내가 가진 비슷한 문제를 해결했습니다! Upvoted. – DNT

관련 문제