I used comma expression in two different ways in the following code.
This code is reduced from some more complex code. I don't have the
ability to write in the 2nd way for the complex code.
I want the output of the 2nd is wanted. Do you have any idea how to
modify the 1st way such that it gives the same output as the 2nd one?
Thanks,
Peng
#include <iostream>
class plot {
public:
plot &doit(int &i){
std::cout << i << std::endl;
return *this;
}
};
int main ()
{
plot p;
int i = 10;
p.doit((++i,i)) .doit((++i,i));// output 12 12; 1st way; not wanted
std::cout << std::endl;
i = 10;
p.doit((++i,i)) ;
p.doit((++i,i)) ; // output 11 12; 2nd way different from above
}
This code is reduced from some more complex code. I don't have the
ability to write in the 2nd way for the complex code.
I want the output of the 2nd is wanted. Do you have any idea how to
modify the 1st way such that it gives the same output as the 2nd one?
Thanks,
Peng
#include <iostream>
class plot {
public:
plot &doit(int &i){
std::cout << i << std::endl;
return *this;
}
};
int main ()
{
plot p;
int i = 10;
p.doit((++i,i)) .doit((++i,i));// output 12 12; 1st way; not wanted
std::cout << std::endl;
i = 10;
p.doit((++i,i)) ;
p.doit((++i,i)) ; // output 11 12; 2nd way different from above
}
Comment