Solved

Returning Object - another question

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

810 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