?
Solved

Returning Object - another question

Posted on 2006-11-25
2
Medium Priority
?
193 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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses

862 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