0

嗨,我正在尝试重载 operator<< 以挂钩

stream << std::endl;

如果我不需要输出,则避免附加 '\n' 。我已经超载了:

std::ostream& operator<< (std::ostream& (*pf)(std::ostream&))
std::ostream& operator<< (std::ios& (*pf)(std::ios&))
std::ostream& operator<< (std::ios_base& (*pf)(std::ios_base&))

但是通话总是在 basic_ostream 结束

_Myt& __CLR_OR_THIS_CALL operator<<(_Myt& (__cdecl *_Pfn)(_Myt&))
{// call basic_ostream manipulator
    _DEBUG_POINTER(_Pfn);
    return ((*_Pfn)(*this));
}
4

1 回答 1

0

自己找到了解决方案

问题是其他重载运算符返回 std::ostream& 因此无法调用重载函数。

于 2016-10-28T08:44:56.157 回答