C++: Difference between revisions

133 bytes added ,  16 October 2021
Line 60: Line 60:
References are like pointers since they do not copy the object except they cannot be null and they cannot be reassigned.<br>
References are like pointers since they do not copy the object except they cannot be null and they cannot be reassigned.<br>
Note that primitives can also be used with references, in which case changes will propagate to the underlying value.<br>
Note that primitives can also be used with references, in which case changes will propagate to the underlying value.<br>
You can also use them as class attributes, initializing them in the constructor's initializer list.
You can also use them as class attributes, initializing them in the constructor's initializer list.<br>
To store references in a vector, you can use <code>std::reference_wrapper</code> and include the <code>functional</code> header.


===String===
===String===