?
Solved

Reference

Posted on 1998-12-18
3
Medium Priority
?
192 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 8

Accepted Solution

by:
Answers2000 earned 120 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

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