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< |
<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 |
void tree<T>::replace_all(T new_value) { |
||
{ |
|||
value = new_value; |
value = new_value; |
||
if (left != |
if (left != nullptr) |
||
left->replace_all |
left->replace_all(new_value); |
||
if (right != |
if (right != nullptr) |
||
right->replace_all |
right->replace_all(new_value); |
||
}</syntaxhighlight> |
}</syntaxhighlight> |
||