C ++, what is the purpose of placing an operator at the end of a class?

Let's say I have a simple C ++ component called Component as follows:

class Component {
 public:
  explicit Component(int i)
  : _integer(i) {
  }

  ~Component() {
  }

  private:
   int _integer;

  Component(const Component&);
  Component& operator=(const Component&);
};

I usually found in the code that I read the last two instructions, but I do not understand this. Is it necessary for the correct use of the component?

+4
source share
2 answers

This announces an overload for operator=. Operator overloading usually allows you to control how assignment expressions ( a = b) are executed .

, , , , , . , (, , , c'tor) Component.

( -) . , . - , , - ++ 03. , .

++ "undefined" , :

Component(const Component&) = delete;
Component& operator=(const Component&) = delete;
+10

.

0

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


All Articles