I have a method that I want to run iteratively on one of two data members, alternating between them. I thought of doing the following
void myClass::alternating_method(){
Graph G;
&G = iteration_number%2 ? &A : &B;
helper_method_which_modifies(G);
iteration_number++;
return;
}
where A and B and iteration_number are all myClass members but I’m not sure it will work. It seems right to me but the style rubs me wrong. The desired result is to call object.alternating_method() in a loop and have it modify object.A and object.B .
Will this work? Is there a better way? Will it have unexpected consequences? Do I need to worry about a destructor being called for G when it goes out of scope?
EDIT: To clarify, I meant helper_method_which_modifies as shorthand for 100 lines containing several methods. The ones that modify G are mostly boost graph methods. Now that I see the answers, it seems the best thing is to have an alternator which does nothing but choose between A and B and then pass the correct variable off to another method.
As already stated by Luchian Grigore, it won’t work because you need a L-value.
The idea is working though with little changes.
Or with a bit more changes: