我有一个很大的整数类,我正在努力使它成为荣誉std::showbase
和std::noshowbase
. 在这里,“荣誉”意味着控制 Integer 类中定义的后缀的使用(而不是C++ 标准行为):
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
and noshowbase
?