Suppose I have objects holding some data:
class myclass
{
//constructors,destructor,setters,getters
private:
int latitude;
int longitude;
}
Say I need to perform some chained operations on these objects, so I can write some functions returning a myclass object to be used inside other functions. Example:
myclass sum (myclass* a, myclass* b)
{
// how to define c?
c.longitude = a->get_longitude() + b->get_longitude();
return c;
}
and another function using the returned object:
int anotherfunc (myclass* a, myclass* b)
{
return a->get_longitude() - sum(a,b).get_longitude();
}
The question is: how should I define the object c
needed for these functions ?
The first idea was to create a dummy object with scope on the file where to store the object c. This approach won't work though in a multithread environment where each thread can perform operations at various times it could lead to troubles.
How to deal with chained operations as stated in a multithreaded program?