Possible Duplicates:
“const T &arg” vs. “T arg”
How to pass objects to functions in C++?
I used the following code to ascertain that C++ on passing objects as const reference the compiler does not make a copy of the object and send the copy. The output confirmed that passing object as const reference does not involve making a copy of the object.
Is there any situation in which passing objects as reference is worse than passing objects as value ( from an efficiency perspective ) ?
class ABC {
public:
int abc_1;
int abc_2;
};
void swapABC ( ABC & _abc_ ) {
_abc_.abc_2 = ( _abc_.abc_1 + _abc_.abc_2 ) - ( _abc_.abc_1 = _abc_.abc_2 ) ;
printf ( "%d\n", ( void * ) &_abc_ ) ;
}
int main ( ) {
ABC x = { 1,2 };
swapABC ( x );
printf ( "%d\n", ( void * ) &x ) ;
return 0;
}