У меня большой целочисленный класс, и я пытаюсь сделать его честью std::showbase
и std::noshowbase
. Здесь, «честь» означает контролировать использование суффикса, как это определено в классе Integer (а не C++ standard behaviors):Как проверить для std :: showbase или std :: noshowbase в операторе вывода?
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'? – 0x499602D2