By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

T* const& a,

P: n/a
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?

Jul 12 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Yes, I think so.

vsgdp wrote:
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?
Jul 12 '06 #2

P: n/a
vsgdp <he***@null.comwrote:
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
--
jb

(reply address in rot13, unscramble first)
Jul 12 '06 #3

P: n/a
vsgdp wrote:
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
Jul 12 '06 #4

P: n/a
Ron Natalie wrote:
vsgdp wrote:
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
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.

Jul 12 '06 #5

P: n/a
Dilip wrote:
>
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*);
Jul 13 '06 #6

P: n/a
Ron Natalie wrote:
Dilip wrote:

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?

Jul 13 '06 #7

P: n/a
Dilip wrote:
Ron Natalie wrote:
>Dilip wrote:
>>>
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
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 13 '06 #8

P: n/a
Dilip <rd*****@lycos.comwrote:
Ron Natalie wrote:
>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

--
Marcus Kwok
Replace 'invalid' with 'net' to reply
Jul 13 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.