大家好!
具有以下代码:
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
我被困住了。帮助我完成部分专业化。
谢谢!