我希望声明一个函数,默认情况下将内容写入std::out
,如果提供了其他输出流,则可以选择启用将内容写入其他输出流。例如:
print_function(std::string & str,
std::ostream & out = std::cout,
std::ostream & other = nullptr) // <-- how to make it optional???
{
out << str;
if (other == something) // if optional 'other' argument is provided
{
other << str;
}
}
设置nullprt
显然不起作用,但是如何做到这一点呢?