A class T
shall provide a member function that copies some but not all member variables (minimal example: just one variable X
) from one object of type T
to another object of type T
. There are two possible solutions, copying from and copying to:
class T {
some_type X;
[...]
void copy_X_from_other( const T& other ) { X = other.X; }
void copy_X_to_other ( T& other ) const { other.X = X; }
};
Are there reasons to prefer one variant over the other? Are there guide lines, best practice examples, or whatsoever?
How should the function be named? An ideal name would be much shorter than copy_(from|to)_other
, yet leave no doubt about the direction of the copying.