… my ZZ object. How can I print its value ?
This is a bit ugly, but works:
(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)
42$1 = (std::ostream &) @0x620020: <incomplete type>
(in this example, the variable x
has the value 42
).
If you don't want the garbage after the value, you can cast to void
:
(gdb) call (void)NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)
42(gdb)
(but note that then there's no newline after the value).
If you're not using namespace std
, you may have to write
(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)('std::cerr', x)
Sometimes cerr
may not be in scope:
(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cerr, x)
No symbol "cerr" in current context.
- then you can try with cout
, but it gets even uglier, because the buffered output has to be flushed:
(gdb) call NTL::operator<<(std::ostream&, NTL::ZZ const&)(cout, x)
(gdb) call 'std::basic_ostream<char, std::char_traits<char>>& std::operator<< <std::char_traits<char>>(std::basic_ostream<char, std::char_traits<char>>&, char const*)'(&cout, "\n")
42