object assignment question

In an assignment like this.
a = b; // same type with array as member.
if object a array is smaller than object b array. Should it error ?

Please show the definition of a and b and their respective types.
I think I got it. This is an assignment, so a will be gone. I was thinking about copy constructor....which a = b doesn't invoke.
The simple answer is to get out of the habit of using arrays, and learn to use STL container classes (such as std::vector). They make this sort of thing so much easier, because they already have sensible operators, constructors and methods defined.

Seriously, you won't regret it.
If you are using arrays and you haven't implemented operator= properly, you will have both a.array and b.array referring to the same array.
class A
{
int a ;
char b;
};

main()
{
A a1,a2;
a1=a2 // shallow copy in this case is safe.
}

but in case class A has a data member such as a pointer i.e int *data in that case simple
assignment will be dangerous in that case you will use Copy Ctor as we not only want to copy simple data members but also the data which is pointed by int *data so a deep copy is required and Copy Ctor serves the purpose
@nmn

In an assignment like this.
a = b; // same type with array as member.
if object a array is smaller than object b array. Should it error ?


if they (data members) are indeed arrays with different sizes then a and b have different types.:)
Of cource you may define the copy assignment operator. In this case you should write copying of the arrays yourself.
Topic archived. No new replies allowed.