Why does std::cout convert volatile pointers to bool?

前端 未结 4 1413
半阙折子戏
半阙折子戏 2020-11-27 22:50

If you try to cout a pointer to a volatile type, even a volatile char pointer where you would normally expect cout to print the string, you will instead simply get \'1\' (as

4条回答
  •  余生分开走
    2020-11-27 23:11

    I think the problem is not an explicit overload for pointers to volatile types, but a LACK of overload for pointers to volatile types. The compiler can't implicitly remove the volatile qualifier from the pointers so it checks available overloads, picks the bool version of operator<< and converts the pointer-to-volatile to bool.

提交回复
热议问题