slapin
I have an array of strings representing objects.
I want to construct the objects without too many ifs.
Array<String> stuff = {
"bh_node1",
"bh_node2",
...
}
Array<TreeElement@> items;
....
for (int i = 0; i < stuff.length; i++) {
if (stuff[i] == "bh_node1")
items.Push(ConstructBhNode1());
else if (stuff[i] == "bh_node2")
items.Push(ConstructBhNode2());
...
}
I’m not really happy with all this long lines with ifs and hardcoding data in code.
Is there some way to produce lists, line in C or C++ where I could just run respective pointer?
Otherwise it looks very annoying and hard to maintain…