c – 花式指针是什么样的?

前端之家收集整理的这篇文章主要介绍了c – 花式指针是什么样的?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
C参考文献提到了一个名为 fancy pointers的概念.我从最近一次严重的投票和后来删除的问题中了解到了它们的存在.

这个定义模糊不清:

When the member type pointer is not a raw pointer type,it is commonly referred to as a “fancy pointer”.

他们的用例示例如下:

An example of a fancy pointer is the mapping address-independent@H_404_12@ pointer boost::interprocess::offset_ptr,which makes it possible to@H_404_12@ allocate node-based data structures such as std::set in shared memory@H_404_12@ and memory mapped files mapped in different addresses in every@H_404_12@ process. Fancy pointers can be used independently of the allocator@H_404_12@ that provided them,through the class template std::pointer_traits.

我不明白这个解释.创建花式指针的语法是什么?为什么我不能在这种情况下使用常规指针?

解决方法

花哨的指针只是一个像指针一样但不是指针的术语.以一个迭代器为例.几乎所有迭代器都是自定义类类型,但它们的行为就像一个指针(有时会有一些限制,你不能完成指针支持的所有操作,因为它们不提供随机访问,但这是一种幻想的一部分.)

换句话说:一个像指针一样的抽象是一个奇特的指针.

猜你在找的C&C++相关文章