void foo( std::string& rs )
{
// There is no way to obtain the real address of object, referenced by rs.
// Isn't it?
}

Re: reference to pointer by tom_usenet

tom_usenet
Mon Dec 15 11:47:15 CST 2003

On Mon, 15 Dec 2003 17:40:47 +0200, "Andy Nikitin"
<andy@mebius-kb.kiev.ua> wrote:

>void foo( std::string& rs )
>{
>// There is no way to obtain the real address of object, referenced by rs.
>// Isn't it?

&rs gives the real address of the object referenced by rs.
e.g.

std::string s;
std::string& rs = s;
assert(&s == &rs); //always works.

Tom

C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html

Re: reference to pointer by a

a
Mon Dec 15 12:02:25 CST 2003

hi

void foo( string& rs )
{
string* s = &rs;
s->assign("newstring");
}

string str("old string");
foo( str );

foo modifies "str" as expected. But why not use rs "as-is" since it
is a direct access to the string anyways.