|
-
March 4th, 2009, 02:01 PM
#1
assignment operator for classes
Getting a little confuse on this part.
I give an example:
Class A{
char *str;
int number;
public:
set(int);
printnumber();
};
int main()
{
A b;
int x =3;
b.set(x);
A c(&b) /*this calls copy constructor which is grand
A d = c /*this calls copy consturctor which is grand
A e;
e=b; /*doesnt call copy constructor*/
e.printnumber();
My question is what does the assignment operator do? Does it just copy the values across from B?
HOw is it different to the copy constructor?
Why do we need to overload the assignment operator if we overload the copy constructor?
I know it will print the value 3 out.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|