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

前端 未结 2 1258
情歌与酒
情歌与酒 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条回答
  •  眼角桃花
    2020-12-16 14:16

    Compile time. In fact, the compiler doesn't even insert runtime code to check that the result is correct. The compiler does check that the conversion is statically possible, of course. Example: casting from a subclass to a superclass. If the conversion requires invoking a builtin or a casting function, they will be executed at runtime, of course, but there will be no type checking.

提交回复
热议问题