T* const& a,

V

vsgdp

Does this mean (T* const)& (i.e., a reference to a constant pointer to a T).
So the pointer is constant but not the object pointed to?
 
J

Jakob Bieling

vsgdp said:
Does this mean (T* const)& (i.e., a reference to a constant pointer
to a T). So the pointer is constant but not the object pointed to?

Yes, the parenthesis are not needed tho.

hth
 
R

Ron Natalie

vsgdp said:
Does this mean (T* const)& (i.e., a reference to a constant pointer to a T).
So the pointer is constant but not the object pointed to?
Here's my little rule in decoding types that works pretty well.
Find the identifier (this is the tricky part, but in this case
it is "a"). If you can go right, go right, if not go left (limits
caused by parens or running out of declaration).

In this case,
a // start at a
is a reference // go left find &
to a constant // go left const
pointer // left *
to type T // left again
 
D

Dilip

Ron said:
Here's my little rule in decoding types that works pretty well.
Find the identifier (this is the tricky part, but in this case
it is "a"). If you can go right, go right, if not go left (limits
caused by parens or running out of declaration).

In this case,
a // start at a
is a reference // go left find &
to a constant // go left const
pointer // left *
to type T // left again

YOu probably know this already but didn't the Vandevoorde/Josuttis C++
Templates book mention an easier way to determine exactly what is const
in an expression?

That is: if you have T* const& a
The token preceding the const is always constant. So we have a
reference to a constant pointer.

so in places where you normally write:
const some_object& x
becomes
some_object const& x

This is probably old news -- it sure did make life easier for my eyes
the past few months.
 
R

Ron Natalie

Dilip said:
YOu probably know this already but didn't the Vandevoorde/Josuttis C++
Templates book mention an easier way to determine exactly what is const
in an expression?
My strategy deals with all aspects of the declaration not just
constness. It's useful when dealing with bizarre things like:
int (*foo[3])(int*);
 
D

Dilip

Ron said:
Dilip said:
YOu probably know this already but didn't the Vandevoorde/Josuttis C++
Templates book mention an easier way to determine exactly what is const
in an expression?
My strategy deals with all aspects of the declaration not just
constness. It's useful when dealing with bizarre things like:
int (*foo[3])(int*);

Uh oh.. is that a pointer to a function returning an int and taking as
argument a pointer to an integer array with 3 elements?
 
V

Victor Bazarov

Dilip said:
Ron said:
Dilip said:
YOu probably know this already but didn't the Vandevoorde/Josuttis
C++ Templates book mention an easier way to determine exactly what
is const in an expression?
My strategy deals with all aspects of the declaration not just
constness. It's useful when dealing with bizarre things like:
int (*foo[3])(int*);

Uh oh.. is that a pointer to a function returning an int and taking as
argument a pointer to an integer array with 3 elements?

No, it's an array (you go right from 'foo' first, and see the '[') of
3 pointers to functions that take a pointer to int and return an int.

V
 
M

Marcus Kwok

Dilip said:
Ron said:
My strategy deals with all aspects of the declaration not just
constness. It's useful when dealing with bizarre things like:
int (*foo[3])(int*);

Uh oh.. is that a pointer to a function returning an int and taking as
argument a pointer to an integer array with 3 elements?

I think foo is an array of 3 elements, and each element is a function
pointer to a function taking a pointer to int as a parameter, and
returning an int.

Like,

typedef int (*P_func)(int*); // Pointer to function taking int* and
// returning int

P_func foo[3]; // array of 3 P_funcs
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top