Copy constructor, destructor and assignment operator. When do we not need them?

I know the C ++ rule, when you add cctor, dtor or op = to your class, you need to add two others so that you work normally in the class under any circumstances.

Is there a case where you do not need to provide all three, only one or two of them?

Why doesn't C ++ require you to add them all if you add one of them to your class?

EDIT1:

You mentioned examples where you do not need not only some of them, but you do not want to have them, so that you make them private or protected. But you still need to write them to your code even with empty bodies.

The only real reason I don't have all of them when you make the polimorphic class by adding a virtual destructor with an empty body. But as soon as you write something in the body of the destructor, you should think about writing something in the body of the document and op = too.

I am looking for examples where you do not need to write all 3 methods, and you can omit some of them without causing errors in your class, even if a beginner uses your class. :)

+5
source share
4 answers

, , , , virtual . " ". , , .

+5

(, ) , op =. ++ , - , , .

, , , , .

+3

, sth, , copy cctor op = dtor.

, , .

++ , , , neseccary.

+1

, , . , ; , , ( ); -, , - , delete this, .

, , , . ( , .)

+1
source

All Articles