vendredi 9 juin 2023

Is the move constructor only come in handy if my class has a member that is a raw pointer?

I am currently studying the move constructor and the copy constructor. Based on my current understanding, these constructors are used to initialize an object of class X by providing another object of the same class type X. However, there is a distinction between the two: the copy constructor takes a non-temporary object as input, while the move constructor takes a temporary object.

Both the copy and move constructors are particularly useful when a class has a member that is a raw pointer, which may point to memory allocated on the heap.

so what if my class doesn`t have a pointer member just a collection of members of integers and strings and array of doubles for example , how would the copy and move constructor be so important and remove the overhead provided by the default argument constructors? and how would the implementation of the two constructors be done in this case? I am taking about the C++ language

I haven`t tried this case yet. but I tried it with the case of my class has a raw pointer

Aucun commentaire:

Enregistrer un commentaire