return of a function

C

costantinos

I have my main and I call another function where I calculate a map<int,
float> and another float number. Is there a way to return both of these
values (the map and the float number) to my main?

Cheers
Costantinos
 
A

Alf P. Steinbach

* (e-mail address removed):
I have my main and I call another function where I calculate a map<int,
float> and another float number. Is there a way to return both of these
values (the map and the float number) to my main?

The ++ in C++ originally denoted classes.

class MapAndFloat ...

MapAndFloat foo() { ... }

or

std::auto_ptr<MapAndFloat> foo() { ... }

if the map is large.

Or you can go for something like

void foo( std::map<int, float>& mOut, double& dOut )
{
std::map<int, float> mResult;
double dResult;

...
mResult.swap( mOut );
dOut = dResult;
}
 
D

David Harmon

On 5 Aug 2006 09:45:39 -0700 in comp.lang.c++, (e-mail address removed)
wrote,
I have my main and I call another function where I calculate a map<int,
float> and another float number. Is there a way to return both of these
values (the map and the float number) to my main?

I would not recommend returning a map<> by value because of the
excessive amount of copying that might result. Instead, declare the
map in main, pass a reference to it to the function and fill it with
values there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top