什么是无效*到什么变量/对象也可以指向 [英] What is void* and to what variables/objects it can point to

查看:142
本文介绍了什么是无效*到什么变量/对象也可以指向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

具体而言,可以将它指向INT /浮动等?
什么样的NSString之类的对象?
任何示例将大大AP preciated。

Specifically, can it point to int/float etc.? What about objects like NSString and the like? Any examples will be greatly appreciated.

推荐答案

无效* 是这样的一个指针,任何指针可以被隐式转换为无效*

void* is such a pointer, that any pointer can be implicitly converted to void*.

例如;

int* p = new int;
void* pv = p; //OK;
p = pv; //Error, the opposite conversion must be explicit in C++ (in C this is OK too)

另外请注意,指针常量不能转换为无效* 没有的const_cast

例如。

const int * pc = new const int(4);
void * pv = pc; //Error
const void* pcv = pc; //OK

Hth以上。

这篇关于什么是无效*到什么变量/对象也可以指向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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