Solved

Returning Object - another question

Posted on 2006-11-25
2
184 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 100 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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

724 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