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

2
  • 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 Commented Nov 3, 2022 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 explanation blog page. Commented Nov 3, 2022 at 16:14

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.