具有以下代码:
template<typename T, typename OutStream = std::ostream> struct print {
OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const {
outStream << toPrint;
return outStream;
}
};
这个调用是错误的:
print<int>(2);
错误信息:
1>main.cpp(38): error C2440: '<function-style-cast>' : cannot convert from 'int' to 'print<T>'
1> with
1> [
1> T=int
1> ]
1> No constructor could take the source type, or constructor overload resolution was ambiguous
这个调用没有错误:
print<int> intPrinter;
intPrinter(2);
我可以在没有实例化的情况下以某种方式使用函数对象吗?我不能在这里使用模板函数,因为我需要部分专业化能力。