What's the difference between cout<<cout and cout<<&cout in c++?

后端 未结 5 1778
余生分开走
余生分开走 2020-12-06 02:59

This might be a beginner question and understanding how cout works is probably key here. If somebody could link to a good explanation, it would be great. cout<

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-06 03:18

    As already stated, cout << cout uses the void* conversion provided for bool testing (while (some_stream){ ... }, etc.)

    It prints the value &cout + 4 because the conversion is done in the base implementation, and casts to its own type, this is from libstdc++:

    operator void*() const
    { return this->fail() ? 0 : const_cast(this); }
    

提交回复
热议问题