Solved

Reference

Posted on 1998-12-18
3
187 Views
Last Modified: 2013-11-20
How a reference to an object is implemented? With the reference a locally declared object can be accessed from another called function. How this is implemented without
passing the address of the object?
0
Comment
Question by:leena_mary
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 30 total points
ID: 1326378
If you mean - how does it work internally : The machine code generated by the compiler uses the address of the object.  The important part is the C++ programmer isn't aware that there is address manipulation going on.

On most compilers these 2 functions will generate identical machine code

void SomeFunc1( int& x ) // reference
{
x = 1 ; // modify reference
}

void SomeFunc2( int * x ) // pointer
{
*x = 1 ;
}


You call these :-

int a ;
SomeFunc1(x) ; // reference call

int b ;
SomeFunc2(&b) ; // pointer call
0
 
LVL 4

Expert Comment

by:pagladasu
ID: 1326379
Answers2000 is right. When a reference to an object is passed as an argument to a function, in reality the address of the object is passed.

0
 

Author Comment

by:leena_mary
ID: 1326380
Here are your points Answers2000.
Thank u pagladasu for your comment.

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pre4 challenge 19 93
zeroMAx challenge 20 87
x-bar in Google Sheets 2 25
Message not shown 5 29
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now