473,395 Members | 1,915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

T* const& 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
8 2449
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hoox2 | last post by:
void push_front(Node const*& head, int data); Can someone tell me what it means for "const*&"? A reference or a pointer?
20
by: christopher diggins | last post by:
I have heard it is considered good practice to pass function parameters as const& as often as possible, is this true? Is it possible to go overboard? And if so why? Thanks a lot in advance...
12
by: zealotcat | last post by:
template <class T> inline T const& max (T const& a, T const& b) { // if a < b then use b else use a return a<b?b:a; } thanks very much!!
25
by: Victor Bazarov | last post by:
In the project I'm maintaining I've seen two distinct techniques used for returning an object from a function. One is AType function(AType const& arg) { AType retval(arg); // or default...
6
by: p|OtrEk | last post by:
What is practic difference between this two declarations? If i want call my func with func("blah") i could write: 1) func(std::string const& arg1) 2) func(const std::string& arg1) Whats better to...
0
by: tom olson | last post by:
After more searching I found that defining const operators can cause problems with many compilers due to the way it interprets the C++ standard. I removed the const operators from my class and it...
13
by: dragoncoder | last post by:
Hi everyone, please consider the following function:- const int& foo ( const double& d ) { return d; } g++ compiles it with warnings and solaris CC gives error. I want to know if the code...
2
by: ek | last post by:
This first example does not work (cannot be overloaded): int& operator()(int a) { // (1) return a; } int const& operator()(int a) { // (2) return a; }
2
by: nassim.bouayad.agha | last post by:
Hello, here is a code snippet showning my problem : template<typename _K> class TClass1 { public: void Process(const _K& arg) const {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.