哪种类型的转换是从Type *到void *? [英] Which kind of cast is from Type* to void*?

查看:173
本文介绍了哪种类型的转换是从Type *到void *?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++中,对于任何数据类型,我可以执行以下操作:

In C++ for any data type I can do the following:

Type* typedPointer = obtain();
void* voidPointer = typedPointer;

当我分配类型时执行转换 void * ?这与

Type* typedPointer = obtain();
void* voidPointer = reinterpret_cast<void*>( typedPointer );

还是其他演员?

推荐答案

这是一个标准的指针转换。由于是标准转换,因此不需要任何显式转换。

It is a standard pointer conversion. Since it is a standard conversion, it doesn't require any explicit cast.

如果要使用显式转换重现该转换的行为, code> static_cast ,而不是 reinterpret_cast

If you want to reproduce the behavior of that conversion with an explicit cast, it would be static_cast, not reinterpret_cast.

在5.2.9 / 2中给出的c $ c> static_cast , static_cast 可以执行可隐式执行的所有转换。

Be definition of static_cast given in 5.2.9/2, static_cast can perform all conversions that can be performed implicitly.

这篇关于哪种类型的转换是从Type *到void *?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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