【发布时间】:2023-04-01 20:01:02
【问题描述】:
我有一个很大的整数类,我正在努力让它尊重std::showbase 和std::noshowbase。在这里,“荣誉”意味着控制 Integer 类中定义的后缀的使用(而不是 C++ standard behaviors):
std::ostream& operator<<(std::ostream& out, const Integer &a)
{
...
if(out.flags() & std::noshowbase)
return out;
return out << suffix;
}
但是,它会导致错误:
$ make static
c++ -DDEBUG -g3 -O1 -fPIC -Wno-tautological-compare -Wno-unused-value -DCRYPTOPP_DISABLE_ASM -pipe -c integer.cpp
integer.cpp:3487:17: error: invalid operands to binary expression ('int' and
'std::ios_base &(*)(std::ios_base &)')
if(out.flags() & std::noshowbase)
~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~
/usr/include/c++/4.2.1/bits/ios_base.h:79:3: note: candidate function not
viable: no known conversion from 'std::ios_base &(std::ios_base &)' to
'std::_Ios_Fmtflags' for 2nd argument
operator&(_Ios_Fmtflags __a, _Ios_Fmtflags __b)
^
1 error generated.
我也尝试过 std::ios::noshowbase 和 std::ios_base::noshowbase 出现类似错误。
如何测试showbase 和noshowbase?
【问题讨论】:
-
你的意思是
out.flags() & std::ios_base::showbase?