re-reviewing the chapter in Lippan and Lajoie C++ Primer the have a
section on references that I don't understand and just makes e shake my
head believing that any behavior is possible with references and that they
can never be understood. Maybe someone else can rephrase this so that I
understand the defined behavior.
cont int ival = 1024;
//error: requires a const reference
int *&pr_ref = &ival; //<<== this seems obvious as a const obj must use
a pointer to a constant object
"Our first attempt to correct the definition is pi_ref might be the
following, but it dos not work-do you see why?
//Still and error (and no, I don't see why)
const int *&pi_ref = &ival;
"If we read this definition from right to left, we discover that pi_ref is
a reference to a pointer to an object of type in defined to be a const (to
which I'm think - yeah - so what! That is exactly what I need!) Our
reference isn't to a constant but rather a noncontant pointer that
addresses a contant object( and why does that not work! i need a point to
a const, not a const pointer!). the correct definition is as follows:
const int ival = 1024;
//ok: this is accepted
int * const &pi_ref = &ival;
(Why - through this I can change the value of a constant object to any
integer)
Ruben
--
http://www.mrbrklyn.com - Interesting Stuff
http://www.nylxs.com - Leadership Development in Free Software
So many immigrant groups have swept through our town that Brooklyn, like Atlantis, reaches mythological proportions in the mind of the world - RI Safir 1998
http://fairuse.nylxs.com DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
"Yeah - I write Free Software...so SUE ME"
"The tremendous problem we face is that we are becoming sharecroppers to our own cultural heritage -- we need the ability to participate in our own society."
"I'm an engineer. I choose the best tool for the job, politics be damned.<
You must be a stupid engineer then, because politcs and technology have been attached at the hip since the 1st dynasty in Ancient Egypt. I guess you missed that one."
© Copyright for the Digital Millennium