Solved

Returning Object - another question

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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. …
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 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.

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now