(void *)铸造有什么用途? [英] What is (void*) casting used for?

查看:70
本文介绍了(void *)铸造有什么用途?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我确实尝试在StackOverflow上搜索此内容,但是我认为由于语法原因,而且不确切知道要搜索的内容,所以我有些不知所措。

I did try searching for this on Stack Overflow, but I think due to the syntax and not knowing exactly what to search I became a little unstuck.

我已经看到(void *)通常用于函数调用。

I have seen (void*) being used to cast, usually to function calls. What is this used for?

推荐答案

void * 通常是指什么?作为 void指针,是一种通用的指针类型,可以指向任何类型的对象。指向不同类型对象的指针在内存中几乎相同,因此可以使用void指针来避免类型检查,这在编写处理多种数据类型的函数时非常有用。

void*, usually referred to as a void pointer, is a generic pointer type that can point to an object of any type. Pointers to different types of objects are pretty much the same in memory and so you can use void pointers to avoid type checking, which would be useful when writing functions that handle multiple data types.

对于C,空指针比C ++更有用。通常应避免使用空指针,而应使用函数重载或模板。类型检查是一件好事!

Void pointers are more useful with C than C++. You should normally avoid using void pointers and use function overloading or templates instead. Type checking is a good thing!

这篇关于(void *)铸造有什么用途?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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