User Defined Conversions in C++

前端 未结 4 2015
遥遥无期
遥遥无期 2020-12-10 14:07

Recently, I was browsing through my copy of the C++ Pocket Reference from O\'Reilly Media, and I was surprised when I came across a brief section and example regard

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-10 14:56

    It was about one of the first things I stumbled across when I was learning C++, so I'd say that no, it is not all that obscure.

    One thing I would caution on though: Use the explicit keyword with them unless you know exactly what you are doing. Implicit conversions can cause code to behave in unexpected ways, so you should avoid using them in most cases. Frankly, I'd be happier if the language didn't have them.

提交回复
热议问题