C++: Difference between revisions

544 bytes added ,  16 October 2021
Line 49: Line 49:
* <code>dynamic_cast</code>
* <code>dynamic_cast</code>
If you're casting between things but do not want to change the bit-pattern (e.g. binary data or pointers), you can also use <code>reinterpret_cast</code>.
If you're casting between things but do not want to change the bit-pattern (e.g. binary data or pointers), you can also use <code>reinterpret_cast</code>.
====References====
References are accepted or store using <code>&<code>.<br>
For example:
<syntaxhighlight lang="c++">
void healPerson(Person &person) {
  person.health = 100;
}
</syntaxhighlight>
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>
You can also use them as class attributes, initializing them in the constructor's initializer list.


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