The difference between copy construct function and assign function of a class

1. The copy construct function creates a new object, while the assign function assigns an object to an existed object.

2. The assign function needs to check if the assignment source and destination are the same, while the copy construct function does not need to do so.

3. The assign function needs to return *this in order to support chain assignment.

4. The assign function needs to free the exist memory space of the destination object.

Advertisements
This entry was posted in C++. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s