좋은 하루 되세요!C++ : 템플릿 : 부분 전문화 : 모든 템플릿 인쇄
다음 코드를 갖는
template<typename T, typename OutStream = std::ostream>
struct print
{
OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const
{
outStream << toPrint;
return outStream;
}
};
template<typename T, typename Index = unsigned int, typename CharType = char, typename OutStream = std::ostream>
struct print<T *, Index>
{
print(CharType delimiter = ' '): delimiter_(delimiter) {}
OutStream &operator()(T const *toPrint, Index startIndex, Index finishIndex, OutStream &outStream = std::cout) const
{
for (Index i(startIndex) ; i < finishIndex ; ++i)
outStream << toPrint[i] << delimiter_;
return outStream;
}
protected:
CharType delimiter_;
};
컴파일러 : MSVCPP10
컴파일러 출력 :
1>main.cpp(31): error C2764: 'CharType' : template parameter not used or deducible in partial specialization 'print<T*,Index>'
1>main.cpp(31): error C2764: 'OutStream' : template parameter not used or deducible in partial specialization 'print<T*,Index>'
1>main.cpp(31): error C2756: 'print<T*,Index>' : default arguments not allowed on a partial specialization
내가 붙어있어. 부분 전문화를 끝내도록 도와주세요.
감사합니다.
내가 [꽤 프린터 라이브러리]에서 당신을 관심 수 있음 (HTTP : //stackoverflow.com/questions/4850473/pretty-print-c-stl-containers)? –
* 더 전문화 된 * 사례로만 전문화 할 수 있습니다. 'T *, Index' 형식은 "특별한"것이 아니라 완전히 다릅니다. –
@KerrekSB 감사합니다. 제안하신 프로젝트는 매우 흥미 롭습니다! – DaddyM