Here is the code:
#include <iostream> #include <iomanip> #include <typeinfo> #if 0 std::ostream &foo(std::ostream &os, std::ios_base &(*x)(std::ios_base &), bool show_id = false) { if ( show_id ) os << "(" << typeid(x).name() << ") "; return os << x; } #endif template<typename T> std::ostream &foo(std::ostream &os, T const &t, bool show_id = false) { if ( show_id ) os << "(" << typeid(t).name() << ") "; return os << t; } int main() { foo(std::cout, std::hex) << 255 << std::endl; foo(std::cout, ".") << std::hex << 255 << std::dec << std::endl; foo(std::cout, std::hex, true) << 255 << std::endl; }
Using bcc32 6.70 and bcc32 5.82, exit
401358255 .ff (std::ios_base & (*)(std::ios_base &) const) 401368255
Using bcc64 6.70 (based on clang) and g ++ 4.8.2, output
ff .ff (FRSt8ios_baseS0_E) ff
I assume that clang and gcc are true because they have a better reputation than bcc32.
If I enable the commenting function, then the bcc32 outputs:
ff .ff (std::ios_base & (*)(std::ios_base &)) ff
What exactly happens with the first version? This is probably a compiler error related to overload resolution, but I can't figure out what bcc32 does or what const is at the end of typeid output.
c ++ operator-overloading overload-resolution c ++ builder c ++ builder-xe6
MM
source share