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? 8 2482
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?
vsgdp <he***@null.com 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?
Yes, the parenthesis are not needed tho.
hth
--
jb
(reply address in rot13, unscramble first)
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
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.
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*);
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?
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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?
|
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 everyone!
Christopher Diggins
http://www.cdiggins.com
|
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!!
|
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 construction and then..
// some other processing and/or changing 'retval'
return retval;
}
|
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 use if i dont want to change content of arg1 it in func
body?
--
<< pozdrawiam -lysek- @ irc.freenode.net#linux.com.pl
<< prompt$ :(){ :|:& };:
<< echo mail | sed 's/__NOSPAM//g'
| |
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 seems to be working fine
now.
>-----Original Message-----
>I have C++ code that has been running just fine in VS6
for
>a couple of years. I brought it into VS.NET with managed
|
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 is correct according to the standard ?
|
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;
}
|
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
{
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| | |