(void *)casting - 这是什么用的? [英] (void*) casting- what is this used for?

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

问题描述

我尝试在SO上搜索这个,但我想由于语法,不知道到底是什么搜索我变得有点不稳。

I did try searching for this on SO 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*, 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.

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

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 *)casting - 这是什么用的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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