Finding the memory address of a pass-by-reference parameter?

S

scott.lewis

Hi,

I'm developing in C++ using Visual Studio 7.1.

Is there any way to get the memory address from a referenced parameter?
In other words, can I find the pointer value as if it were passed in as
a pointer?

For example:

void compare (int& ref_value, int* pointer_value)
{
// is there any way to determine if these two are referencing the same
// memory address?
}

Thanks for your help!

-Scott-
 
J

Jakob Bieling

void compare (int& ref_value, int* pointer_value)
{
// is there any way to determine if these two are referencing the same
// memory address?

Use the address-of operator as you would outside the function when
passing the pointer to the int.

hth
 
A

Andrew Koenig

Is there any way to get the memory address from a referenced parameter?
In other words, can I find the pointer value as if it were passed in as
a pointer?

For example:

void compare (int& ref_value, int* pointer_value)
{
// is there any way to determine if these two are referencing the same
// memory address?
}

if (&ref_value == pointer_value) { /* ... */ }

The point is that ref_value is in all respects nothing more than another
name for the object that was passed as argument. Therefore, &ref_value is
the address of that object.
 
R

Ron Natalie

void compare (int& ref_value, int* pointer_value)
{
// is there any way to determine if these two are referencing the same
// memory address?

if(&ref_value == pointer_value) ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top