c++ - 花哨的指针是什么样子的?

标签 c++ pointers

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.

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

最佳答案

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

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

关于c++ - 花哨的指针是什么样子的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43472083/

相关文章:

c++ - 基类构造函数不会调用派生类版本的虚方法

c++ - 在 C++ 中全局使用二维数组

c - C中枚举值的内存位置

C、如何调用一个函数

c++ - 有人可以帮助这个程序中的错误吗?

c++ - 使用图形中的 Blender 和 Bloom 效果为游戏创建 3D 模型

c++ - 将 char* 转换为 int 并转换回相同的 char 数组

arrays - Rust 中指向行的指针

c++ - 使用设计模式时 'pointer to a function'的优势

c++ - 可变参数模板复杂继承生成