c++ – What is The Rule of Three? – Stack Overflow

The rule of three

Sometimes you need to implement a class that manages a resource.(Never manage multiple resources in a single class,this will only lead to pain.)In that case, remember the rule of three:

If you need to explicitly declare either the destructor, copy constructor or copy assignment operator yourself, you probably need to explicitly declare all three of them.

(Unfortunately, this “rule” is not enforced by the C++ standard or any compiler I am aware of.)


Most of the time, you do not need to manage a resource yourself,because an existing class such as std::string already does it for you.Just compare the simple code using a std::string memberto the convoluted and error-prone alternative using a char* and you should be convinced.As long as you stay away from raw pointer members, the rule of three is unlikely to concern your own code.

Full Article @ stackoverflow.com

This entry was posted in Uncategorized. 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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s