0

In C++, is there a difference between declaring a copy constructor default as opposed to not declaring one at all? For visualization:

class A{
   int x;
}

vs

class B{
   int x;
   B() = default;
   B(const B&) = default;
}

How about default copy assignment, default move constructor, and default move assignment? If I'm just going to declare them as default, could I just as well not declare them at all?

I looked on the internet and haven't been able to find an answer

  • Thanks! the second response in that linked post answers my questions. I wonder if there's a way to make that answer easy to find through browser search engines – Injenye Lojik Nov 03 '22 at 15:52
  • `B(const B&) = default;` suppresses the compiler from generating an implicit `B(B&&)` move constructor, implicit `B& operator=(B&&)` move assignment, and will eventually also suppress an implicit `B& operator=(B const&)` copy assignment. q.v. the table at the bottom of [Howard Hinnant](https://howardhinnant.github.io/classdecl.html) explanation blog page. – Eljay Nov 03 '22 at 16:14

0 Answers0