간단한 텍스트 분석기를 구축 중입니다. 나는 그것을 컴파일하려고하면오류 : 잘못된 템플릿 인수 수 (0, 1이어야 함)
template<typename FwdIt0, typename FwdIt1, typename Comp, typename Num>
Num SmartAnalyzer::count_intersection(FwdIt0 beg0, FwdIt0 end0, FwdIt1 beg1, FwdIt1 end1, Comp less, Num n)
{
while (beg0 != end0 && beg1 != end1)
{
if (less(*beg0, *beg1)) ++beg0;
else if (less(*beg1, *beg0)) ++beg1;
else
{
++n;
++beg0;
++beg1;
}
}
return n;
}
// Finds intersection between 2 sentences and divide it to the average sentence length
template<typename FwdIt0, typename FwdIt1>
double SmartAnalyzer::intersection_weight(FwdIt0 beg0, FwdIt0 end0, FwdIt1 beg1, FwdIt1 end1)
{
double const mid_size = 0.5 * (std::distance(beg0, end0) + std::distance(beg1, end1));
/* LINE 38 */ double const intsc = count_intersection(beg0, end0, beg1, end1, std::less<>(), double());
return intsc/mid_size;
}
, 내가 갖는 : GCC 4.7 on Debian
와
../lib/analyzer.cpp: In member function ‘double SmartAnalyzer::intersection_weight(FwdIt0, FwdIt0, FwdIt1, FwdIt1)’ :
../lib/analyzer.cpp : 38 : 76 : error : wrong number of template arguments(0, should be 1)
나는 다음과 같은 코드가 있습니다. 나는 이것이 4.7+가 템플릿 별칭을 지원하지 않을 때까지 어떻게 든 그 GCC와 관련이 있다고 생각하지만 어떻게 고칠 수 있는지 전혀 모른다. gcc를 4.8로 업데이트 할 수있는 기회가 없습니다.
템플릿을 사용하고 인스턴스를 생성하려고 시도하는 analyzer.cpp의 38 줄을 보여주십시오. – jsantander
가능한 중복 http://stackoverflow.com/questions/7721244/c-template-function-specialization-wrong-number-of-template-arguments 및 http://stackoverflow.com/questions/22097240/c-wrong-number -of-template-arguments-2-should-be-1 – Rakib
@jsantander 내 질문을 편집했습니다. – Deepsy