KonZa <
XXXX@XXXXX.COM >writes:
Quote
>The initialization of i takes a reference to employee as its argument.
>This means that the employee copy constructor will be used to
>initialize i.
so if the employee class doesn't has a copy constructor neither &=
operator overloaded bad things could happend.
First of all, your question doesn't have anythign to do with operator&=();
That operator is used for bitwise "ANDing" in a value into another value.
Do you mean the copy-assignment operator (operator=())? It isn't invoked here,
either, but its function is somewhat similar to that of the copy constructor.
Second, the employee class is very likely to have a copy constructor. If
you don't "manually" declare the copy constructor in the class definition,
the compiler will generate one that will perform a member-wise copy of
employee objects. In most cases, this is exactly what is needed.
Bad things will only happen if the copy constructor (user-defined or
compiler-generated) doens't do what it should do. I can't tell from here
if this is the case with your employee class.
Quote
so this is solved either using a copy constructor or the &= oeprator
overloading right?
Again, operator&=() is not involved.
*Using* a copy constructor does not solve anything. The copy constructor
is used, and you can't do anything about it. Depending on the intended
behavior of employee objects, you might have to provide the copy constructor
yourself.
If you provide the copy constructor yourself, you should consider if you
should also provide the copy-assignment operator. Often, the destructor of
such class has to be user-defined as well.