-3

Can any one tell why do we have copy and move constructors and assignments are explicitly deleted how it impacts on class behavior

class System : public std::enable_shared_from_this<System> {
  public:
    System();
    virtual ~System();
    System(const System&) = delete;
    System(System&&) = delete;
    System& operator=(const System&) = delete;
    System& operator=(System&&) = delete;
     ---
   }
Kvn Reddy
  • 1
  • 3
  • 4
    There's only one destructor, the rest are various constructors and two stray assignment operators. Why do you think that's "too many" ? – Quentin Apr 28 '21 at 07:40
  • 9
    I can see only one constructor, the other declarations are deleting the default constructors and assignment operators. – bereal Apr 28 '21 at 07:41
  • 4
    There is one default constructor, one destructor, then the copy and move constructors are explicitly deleted, and then the copy and move assignments are also deleted. So, in total there is exactly one constructor and one destructor, which isn't very many at all. You should probably get yourself [a good book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). – molbdnilo Apr 28 '21 at 07:45
  • Is there any chance that your actual doubt is why the copy and move constructors are explicitly deleted and how does it affect the behaviour of the class? – Bob__ Apr 28 '21 at 08:12
  • yes my intention is why the copy and move constructors are explicitly deleted – Kvn Reddy May 01 '21 at 18:39

1 Answers1

-1

What is confusing you, most likely is the inheritance. When you write class myclass : public baseclass the compiler auto-generates you a constructor, destructor, copy-constructor, and assignment operators. These are basic functions that, until redefined, have an empty body, only calling the base class's respective functions. This is what you see here, deleting all, but the constructor and destructor.

Also, note that you can overload a function virtually infinite times, including the constructor, so you can have more than one.

Szabó Áron
  • 185
  • 1
  • 4