Suppose I have two functions, one returns a reference to an object and the other returns an object by value. See below:
What is the difference between the statements below?
What is it's impact on efficiency?
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -
Code:
// Assume 'B' is a well-defined class
B& fn(B& b) // returns an object reference
{
b.i++ ;
return b ;
}
B fn2(B& b) // returns an object by value
{
b.i++
return b ;
}
What is the difference between the statements below?
What is it's impact on efficiency?
Code:
// Assume 'B' has a member function called 'doIt'
fn().doIt() ;
fn2().doIt() ;
Rome did not create a great empire by having meetings, they did it by
killing all those who opposed them.
- janvier -