简体   繁体   English

花式指针是什么样的?

[英]How does a fancy pointer look like?

The C++ reference mentions a concept called fancy pointers . C++ 参考文献提到了一个叫做花式指针的概念。 I learned about their existence from a recent heavily downvoted and afterwards deleted question.我从最近一个被严重否决且随后被删除的问题中了解到它们的存在。

The definition is rather vague:定义比较模糊:

When the member type pointer is not a raw pointer type, it is commonly referred to as a "fancy pointer".当成员类型指针不是原始指针类型时,通常称为“花式指针”。

Their use case example is:他们的用例示例是:

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.花哨指针的一个例子是映射地址无关指针 boost::interprocess::offset_ptr,它可以在共享内存中分配基于节点的数据结构,例如 std::set 和映射到不同地址的内存映射文件每一个过程。 Fancy pointers can be used independently of the allocator that provided them, through the class template std::pointer_traits.花式指针可以通过类模板 std::pointer_traits 独立于提供它们的分配器使用。

I don't understand that explanation.我不明白那个解释。 What is the syntax for creating a fancy pointer and why can't I use a regular pointer in this case?创建精美指针的语法是什么,为什么在这种情况下我不能使用常规指针?

A fancy pointer is just a term for something that acts like a pointer but is not.花哨的指针只是一个类似于指针但不是指针的东西的术语。 Take, for example, an iterator.以迭代器为例。 Pretty much all iterators are custom class types, but they behave just like a pointer (sometimes there are restrictions and you cannot do all the operations supported by a pointer as they do not provide random access but that is part of the fanciness.)几乎所有迭代器都是自定义类类型,但它们的行为就像一个指针(有时存在限制,你不能执行指针支持的所有操作,因为它们不提供随机访问,但这是幻想的一部分。)

To put it another way: An abstraction that acts like a pointer is a fancy pointer .换句话说:一个像指针一样的抽象是一个花哨的指针

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当C ++被当作数组对待时,如何看待指向无符号字符的指针? - How does C++ look at a pointer to an unsigned char when it's treated like an array? 当重载的运算符new通过一个额外的前缀使指针偏移时,有问题的情况类别看起来像 - When an overloaded operator new offsets a pointer by an additional prefix, how does the class of problematic cases look like 二进制文件应如何显示? - How does binary file should look like? OBEX 协议是什么样的? - How does the OBEX protocol look like? 如何查看指针映射中的指针是否不为0 - How to look if a pointer in a pointer map is not 0 模糊高斯算法的外观如何? 有实施示例吗? - How does a blur gauss algorithm look like? Are there examples of implementation? UnaryFunction在std :: for_each中的外观如何 - How does the UnaryFunction look like in std::for_each 对于opencv minMaxLoc,cv :: mask应该如何? - How does cv::mask should look like for opencv minMaxLoc? 如何实现一个operator->用于指向外部存储器的花哨指针? - How do I implement a operator-> for a fancy pointer to external memory? 如果我有一个向量(或类似的东西)成员变量,move构造函数的外观如何? - How does the move constructor look like if I have a vector (or anything like it) member variable?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM