Is static_cast(…) compile-time or run-time?

前端 未结 2 1257
情歌与酒
情歌与酒 2020-12-16 13:47

Is static_cast(...) something that gets done at compile-time or run-time? I\'ve googled around but I got different answers.

Also, dynami

2条回答
  •  萌比男神i
    2020-12-16 14:33

    Depends on what you are casting to what else. E.g. static_cast("Hello") ends up calling std::string constructor.

    Off the top of my head, I can't think of any case where reinterpret_cast would need to generate actual machine instructions. It's just telling the compiler: take this bit pattern, and believe it to be a value this type.

提交回复
热议问题