This is my first post and I hope I'm doing it ok. I have tried to solve this problem for a while now but just went for an intermediary variable in the meantime. Well this is what I mean:
//from a pre-built library
double getValue(int idx)
{
//Returns some value from within a class
}
//from a function I created
void setValue(double &input)
{
//set some value here
}
I am currently doing my program as follow:
double numberOne;
numberOne = getValue(0);
setValue(numberOne);
This works and compiles. I would like to however do something as follows:
setValue(getValue(0));
However I can't seem to get it right (have tried a number of referencing\de-referencing things but I'm just shooting in the dark). I would like to know if it's even possible to do so? Furthermore if it is possible to do so, is there any speed\memory space advantages to perform it this way rather than having an intermediary storage value (aka numberOne). It really isn't a concern for a type double value but when its a class with a much larger footprint then I would like to reduce the amount of memory usage\deep copying as much as possible for speed\memory considerations.
On a side note are there any books or online resources that can help me to speed up my C++ programs with other efficiency improvements to speed\memory usage.
Thanks so much in advance for any help you may be able to provide.
setValuepotentially changes its input, how are you going to notice that change if you pass something that you cannot later query? There is a reason references to non-const don't bind to rvalues.