why is std::cout convertible to void* if using g++?

前端 未结 3 1720
后悔当初
后悔当初 2021-01-02 00:22

Why can one cast a std::ostream to a void pointer? I am not aware of any such conversion operator in std::ostream. Code below

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-02 01:06

    Answering only the follow-up, since nicebyte's answer is perfect for the original question.

    Chances are, your gcc is set up to use libstdc++ (which hasn't changed the operator yet due it being an ABI-breaking change), and your clang is set up to use libc++ (which was from the beginning intended as a C++11 standard library and isn't quite conformant in C++98 mode - it provides a bool conversion operator that is explicit in C++11).

提交回复
热议问题