Categories Java

A Complete Guide to C++[EN]

  1. Use the return type of const T& to avoid modifying it directly (like assignment). Similarly with variable types. This typically goes hand in hand with objects created by pointers. In contrast, returning by value usually involves objects. The advantage of returning by value is that it creates a new object, having no impact on the input (since returning it calls the copy constructor).
  1. Returning a reference does not mean it cannot be immutable. For example, the copy assignment operator returns a reference but behaves just like returning a value (the term “copy” emphasizes its immutability).
  2. If the type is T&&, it is usually associated with move semantics (move constructor, move assignment) used with objects that are returned but not yet assigned.
  3. The output of dereferencing *T is similar to the output of a function call, returning an rvalue. Arithmetic operators can be used to iterate over it (++, –, +/- number). You can also use the static functions std::prev and std::next to traverse it.
  4. The output of dereferencing *T is similar to the output of a function call, returning an rvalue. Arithmetic operators can be used to iterate over it (++, –, +/- number). You can also use the static functions std::prev and std::next to traverse it.
  5. Generic in C++ always comes with the general typename keyword. If not, use the class keyword.
  6. using and typedef are almost similar but using is more powerful and modern (works with typename.)

More From Author

Leave a Reply

Your email address will not be published. Required fields are marked *