Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Returning Object - another question

Posted on 2006-11-25
2
Medium Priority
?
191 Views
Last Modified: 2010-04-01
Hi there,

This is a follow up question on the previous one, since I already accepted an answer there I am reposting the question here:-)

In this example,

void C::getB(B& r )
{
     B b;
    //do some initialization of B here
    r = b;
}

Can I write directly to r without having to create b?

void C::getB(B& r )
{
     r.somthing = 2; /// things like this...
}
0
Comment
Question by:ambuli
[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
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 18012541
That works also, since B exists in the scope of the calling function. Yet the naming would be poor, I'd rather call that

void C::SetSomethingInB(B& r )
{
     r.somthing = 2; /// things like this...
}
0
 

Author Comment

by:ambuli
ID: 18012605
Thanks you. That was just an example... that is why I didn't bothered about naming....
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

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

610 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