void-pointer
void-pointer

Reputation: 14827

Generalized name for pointers and {l,r}value references?

Do pointers and {l,r}value references belong to the same group of type decorations that signifies how a type should be accessed? If so, what is the name of this group? For example, {const, volatile, restrict} are all type qualifiers. I am looking for a name like this that can be applied to pointers and references of all kinds (and one that is hopefully mentioned in the standard somewhere).

Thanks for your insight!

Upvotes: 0

Views: 159

Answers (3)

Jonathan Wakely
Jonathan Wakely

Reputation: 171303

According to the C++ grammar they are both called a ptr-operator when they occur in a ptr-declarator, as defined in [dcl.decl]/4

ptr-operator:
    * attribute-specifier-seqopt cv-qualifier-seqopt
    & attribute-specifier-seqopt
    && attribute-specifier-seqopt
    nested-name-specifier * attribute-specifier-seqopt cv-qualifier-seqopt

But that's just the formal name in the grammar, in terms of how you use pointers and references they are not similar and I don't think there's much value in grouping them together. Pointers are objects and can be copied, passed by value, re-assigned etc. whereas references can't do any of those things, they're a completely different language construct. Trying to group them into something that "signifies how a type should be accessed" is a mistake IMHO.

Upvotes: 3

fredoverflow
fredoverflow

Reputation: 263128

Something that takes a type and gives you back another type is usually called a type constructor. For example, the type constructor * takes a type T and gives you back another type pointer to T.

Upvotes: 0

Cheers and hth. - Alf
Cheers and hth. - Alf

Reputation: 145279

AFAIK the C++ standard doesn’t name the group of “type decorators” that include pointer and reference, but you can refer to them as type builders.

Corresponding built in type builders in other languages use different syntax.

The template mechanism in modern C++, combined with C++11 using, lets you define custom type builders, and it can be argued that ideally we should now switch over to that instead of the “experiment that failed” C syntax…

E.g.,

template< class Pointee >
using Ptr = Pointee*;

template< class Referent >
using Ref = Referent&;

int main()
{
    Ptr<int> p = new int( 42 );
    Ref<int> r = *p;
}

However, as of August 2012 this syntax is not yet supported by Visual C++.

Upvotes: 1

Related Questions