Solved

Reference

Posted on 1998-12-18
3
186 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
Comment Utility
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
Comment Utility
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
Comment Utility
Here are your points Answers2000.
Thank u pagladasu for your comment.

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

762 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

14 Experts available now in Live!

Get 1:1 Help Now