Having the following code:
template<typename T, typename OutStream = std::ostream> struct print {
OutStream &operator()(T const &toPrint, OutStream &outStream = std::cout) const {
outStream << toPrint;
return outStream;
}
};
This call is erroneous:
print<int>(2);
Error message:
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
This call is not erroneous:
print<int> intPrinter;
intPrinter(2);
Can I use a function object somehow without its instantiation? I cannot use a template function here, because I need partial specialization capabilities.