是static_cast< T>(...)编译时还是运行时? [英] Is static_cast<T>(...) compile-time or run-time?

查看:118
本文介绍了是static_cast< T>(...)编译时还是运行时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static_cast< T>(...)是在编译时或运行时完成的吗?我在Google周围搜索,但得到了不同的答案。

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

此外, dynamic_cast< T>(...)显然是运行时-但是 reinterpret_cast< T>(...)

Also, dynamic_cast<T>(...) is obviously runtime - but what about reinterpret_cast<T>(...)?

推荐答案

取决于您要投射的内容还有什么例如。 static_cast< std :: string>( Hello)最终调用 std :: string 构造函数。

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

我想不起,在任何情况下 reinterpret_cast 都需要生成实际的机器指令。只是告诉编译器:采用这种位模式,并认为它是这种类型的值。

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.

这篇关于是static_cast&lt; T&gt;(...)编译时还是运行时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆