在C/C ++中使用void指针 [英] usage of void pointer in c/c++

查看:116
本文介绍了在C/C ++中使用void指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我想知道在使软件更安全,更灵活方面,虚指针在现实世界中如何应用. 例如,我知道无效指针(将其强制转换为什么指针)隐藏在外部,这将使软件更加安全. 还有其他原因为什么要使用空指针?

Hey, I am wondering how void pointers is applied in the real world in terms of making a software more secure, more flexible. For example, I know that void pointers, what pointer it will cast to is hidden to outside, which will make a software more secure. Are there other reasons why you would use void pointers?

推荐答案

无效指针不会使软件更加安全.

Void pointers don't make the software any more secure.

在c中使用void *的原因是一种多态性-如果您不知道数据将是哪种类型,则可以传递void *

The reason to use void* in c is a form of polymorphism - if you don't know what type the data will be you can pass a void*

在C ++中,不需要使用void *,并且该语言阻止了某些C语言的使用

In C++ there is less need to use void* and the language prevents some of the C uses

这篇关于在C/C ++中使用void指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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