微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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
pointer boost::interprocess::offset_ptr,which makes it possible to
allocate node-based data structures such as std::set in shared memory
and memory mapped files mapped in different addresses in every
process. Fancy pointers can be used independently of the allocator
that provided them,through the class template std::pointer_traits.

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

解决方法

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

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

原文地址:https://www.jb51.cc/c/110461.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐