Solved

Reference

Posted on 1998-12-18
3
190 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 55
Fibonacci challenge 11 136
changeXy challenge 13 93
wordappend challenge 8 223
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 …
In this post we will learn different types of Android Layout and some basics of an Android App.
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.

733 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