Is a copy constructor created by default?

As I knew until today, when creating a new class, four things are created by default. Default Constructor, Destructor, Copy Constructor, and Assignment Operator. But today, when I was going through the C ++ article, he said that there may be situations where the copy constructor is not created by default.

  • It's true?
  • If so, in what situations?
  • In such situations, how can you pass an instance of this class by value?
+4
source share
2 answers

1) Yes, there may be situations where the copy constructor is not created by default.

2) , , 12.8 [class.copy]:

12.8.7 , - . , , . - , .

...

7 , . , ; , (8.4). , .

12.8.11 , . , - , , delete d:

11 / . / X (8.4.3), X :

- X - ,

- M ( ), /, (13.3), Ms , , , ,

- B, /, (13.3), Bs, , ,

- , , ,

- , rvalue

...

3) ( , default , , ).

+5

, . , / (, ), . , / , .

. (, std::unique_ptr) . ( , ) , , . , "" ( , ), , , .


... const-reference vs , , . Boost " " (call_traits <T> :: param_type) const, . (, , , , ) . , , , , , , .

, , ( ).

0

Source: https://habr.com/ru/post/1544699/


All Articles