은 기본적으로는 표준 : : 목록 같은 것을 통해 루프 (이것은 일반적으로 만들고, 다른 문자열) STL 문자열의 STL 컨테이너보고 최장의 길이를 반환합니다 공통점. 그것은 다음과 같이 파일 목록을 처리이다 :
C:\Windows\System32\Stuff.exe C:\Windows\Things\InHere.txt C:\Windows\Foo\Bar.txt
이 11을 반환해야한다 "C:\Windows\
는"공통이기 때문이다.
전에 templatized 함수를 작성하지 않았으며 제 컴파일러가 불평하고 있습니다. 여기 내 코드는 다음과 같습니다
헤더 :
// longestBegin.h -- Longest beginning subsequence solver
template <typename SequenceSequenceT, typename SequenceT, typename T >
size_t longestBegin(InputIterator firstCandidates, InputIterator lastCandidates);
구현 :
// longestBegin.cpp -- Longest beginning subsequence solver
#include <stdafx.h>
template <typename SequenceSequenceT, typename SequenceT, typename T >
size_t longestBegin(InputIterator firstCandidates, InputIterator lastCandidates)
{
SequenceT firstString = *firstCandidates;
size_t longestValue = firstString.length();
firstCandidates++;
for(size_t idx = 0; idx < longestValue; idx++)
{
T curChar = firstString[idx];
for(InputIterator curCandidate = firstCandidates;curCandidate != lastCandidates; curCandidate++)
{
if ((*curCandidate)[idx] != curChar)
return idx - 1;
}
}
return longestValue;
}
내가 내가 여기에 근본적인 뭔가를 누락 재미있는 느낌이 ......
컴파일러 폭탄이 다음 오류와 함께 표시됩니다.
error C2998: 'size_t longestBegin' : cannot be a template definition
아이디어가 있으십니까? 감사!
빌리 3
여기에 저작권 메시지를 제거하여 코드의 가독성을 높이십시오. –
코드에서 오류 메시지가 나타나는 곳을 표시하십시오. –
그래, 위의 설명을 복사하면 도움이되지 않습니다. –