Default copy constructor and assignment for class with move constructor and assignment

后端 未结 2 1888
轻奢々
轻奢々 2020-12-30 15:31

Let\'s say I have this class:

class Test
{
public:
    Test();
};

AFAIK, compiler provides default copy constructor and assignment operator

2条回答
  •  天涯浪人
    2020-12-30 16:19

    According to section 12.8 Copying and moving class objects of the C++ Standard

    7 If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; otherwise, it is defined as defaulted (8.4).

    18 If the class definition does not explicitly declare a copy assignment operator, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy assignment operator is defined as deleted; otherwise, it is defined as defaulted (8.4).

    So in your case and the copy constructor and the copy assignment operator are implicitly declared by the compiler but defined as deleted.

提交回复
热议问题