什么是你在C / C ++项目中使用的指针到指针和/或引用到指针的最有用的时间呢? [英] What was the most useful time you used a pointer-to-pointer and/or reference-to-pointer in a c/c++ project?

查看:117
本文介绍了什么是你在C / C ++项目中使用的指针到指针和/或引用到指针的最有用的时间呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指针到指针和引用到指针开始看起来过于复杂,尤其是对新手。什么是你在一个C / C ++项目中使用一个你工作的最好的和最有用的原因是什么?

Pointers-to-pointers and references-to-pointers seem overly complicated at first, especially for newbies. What is the best and most useful reason you used one in a c/c++ project you worked on?

这可以帮助人们更好地了解指针和如何有效地使用它们。

This can help people better understand pointers and how to use them effectively.

编辑:所含C以及C ++

Edited: Included C as well as C++

推荐答案

由于没有人提到这还没有,他们可能是迭代器有用的。

Since no one has mentioned this yet, they may be useful as iterators.

假设你有某种对象的列表。你需要穿越一些人在某些特定的顺序。

Assume you have a list of objects of some sort. And you need to traverse some of them in some specific order.

所以,你创建一个数组持有指针,你需要遍历的对象,然后进行排序的数组。

So you create an array holding pointers to the objects you need to traverse, and then you sort that array.

成数组迭代器是一个指针的指针。

An iterator into that array is a pointer to a pointer.

与排序它的std ::排序要求对迭代器,这意味着它需要对指针的指针。

Sorting it with std::sort requires a pair of iterators, which means that it requires a pair of pointers to pointers.

然后用的std :: for_each的穿越这还需要一对迭代器。

And then traversing it with std::for_each also requires a pair of iterators.

这是在我最后一次使用指针的指针的上下文。 (其实我有一个抽象最后一层,所以我结束了与指针的指针的指针,但是这可能更不寻常的)

That's the context in which I last used pointers to pointers. (I actually had one final layer of abstraction so I ended up with pointers to pointers to pointers, but that's probably more unusual)

这篇关于什么是你在C / C ++项目中使用的指针到指针和/或引用到指针的最有用的时间呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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