Parametric polymorphism: Difference between revisions

Content added Content deleted
m (→‎{{header|Wren}}: Changed to Wren S/H)
m (→‎{{header|C++}}: formatting and nullptr instead of NULL)
Line 199: Line 199:
=={{header|C++}}==
=={{header|C++}}==


<syntaxhighlight lang="cpp">template<class T>
<syntaxhighlight lang="cpp">template<typename T>
class tree
class tree {
{
T value;
T value;
tree *left;
tree *left;
Line 212: Line 211:


<syntaxhighlight lang="cpp">template<class T>
<syntaxhighlight lang="cpp">template<class T>
void tree<T>::replace_all (T new_value)
void tree<T>::replace_all(T new_value) {
{
value = new_value;
value = new_value;
if (left != NULL)
if (left != nullptr)
left->replace_all (new_value);
left->replace_all(new_value);
if (right != NULL)
if (right != nullptr)
right->replace_all (new_value);
right->replace_all(new_value);
}</syntaxhighlight>
}</syntaxhighlight>