C ++指针用法 [英] C++ Pointers usage

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

问题描述

最近,我一直在研究C ++中的Pointers.根据我所读的内容,指针变量用于通过引用(类似于VB中的ByRef)或函数指针(在C#中为委托)传递变量.我敢肯定,指针的用法并不局限于这些示例.我希望了解一些需要指针的应用程序.网络上的大多数教程都试图解释按引用传递的用法. 在此先感谢您,并感谢您提出的麻烦问题:)

Recently, I've been dabbling with Pointers in C++. According to what I've read, pointers variables are used to pass variables by reference (similar to ByRef in VB) or function pointers (delegates in C#). I'm pretty sure pointer usage is not confined to these examples. I was hoping to know some applications where pointers are necessary. Most tutorials on the net try to explain the pass by reference usage. Thanks in advance and sorry for the noobish question :)

推荐答案

通常,只有在没有其他选择时,才可以使用指针.例如,在C语言中,无法将变量通过引用"传递给函数.

Generally you can use pointers only when you don't have any other option. For eg In C there is no way of passing a variable "by reference" to a function.

在C ++中没有指针的情况下,您也无法真正实现运行时多态.

Also in C++ without pointers you can't really achieve run time polymorphism.

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

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