I've already asked some people about this on AIM but I decided to just formaly ask it on the boards as well. I have several questions
Whenever you initialize an object of a class, e.g
does the '=' operator *always* decide what constructor to call? e.g-- in the example above, would the = operator examine the two operands and then instruct the compiler to call the copy constructor?Code:class_name ob1 = ob2; //ob2 previously declared
and then for something like:
I already asked some people, and they said that this statement will call the class_name(int) constructor.Code:class_name ob1=5;
but then, if you have:
the assignment operator here does not call any constructor, correct? the code that facilitates the actual copy is located within the operator function itself? if so, what is the point of (copy) constructors at all? couldn't the necessary code just be in the operator function?Code:class_name ob1; class_name ob2; ob1=ob2;
and then finally: i think i read somewhere that there is a fundamental difference between objects initialized to a user-defined value and objects just declared and then later assigned that same value is that true?, e.g
like one is a default initialization, then assignment, and the other is a non-default initialization?Code:class_name ob1; class_name ob2; ob1=ob2; //is there something different here class_name ob3=ob1; //than here?
so then is there a difference in how the '=' operator acts in these expressions?
phew... i think thats everything... thanks to anyone who has any input