web123456

C++ Basics

1.

​​​​​​​​​The clever use of =delete in C++11_= delete-CSDN blog

If the member function of the class is modified with "=delete" later, it means that the function cannot be called again, otherwise an error will occur.

2.Move constructor

(Excerpt from the Zhipu Qingyan)

Special member function that allows the state of one object to another newly created object without copying.

This is a new feature introduced in the C++11 standard, designed to improve performance, especially when it comes to temporary objects and resource management.

  1. class MyClass {
  2. public:
  3. MyClass(MyClass&& other) noexcept : member(std::move()) {
  4. // Ownership of mobile resources
  5. }
  6. // Other member functions and member variables...
  7. private:
  8. SomeResourceType member;
  9. };

MyClass&& other: This is an rvalue reference parameter pointing to the object to be moved. The rvalue reference allows us to access objects that are about to be destroyed and “steal” resources from them.

noexcept:

This keyword means that the move constructor will not throw an exception. This is an optimization tip that tells the compiler to use the mobile constructor safely when needed.