Suppose I have a data type enum TreeTypes { TallTree, ShortTree, MediumTree }.
And I have to initialize some data based on one specific type of tree.
I have currently written this code:
int initialize(enum TreeTypes tree_type) {
if (tree_type == TallTree) {
init_tall_tree();
}
else if (tree_type == ShortTree) {
init_short_tree();
}
else if (tree_type == MediumTree) {
init_medium_tree();
}
return OK;
}
But this is some kind of silly code repetition. I do not use any of the powerful C ++ features such as templates.
How can I write this code better?
Thanks, Boda Sido.
source
share