Pass a type into a function or something else?

Pages: 12
Worked perfectly! Problem solved with templates. Thanks all.
@Abramus:
From the information I was initially presented, no, the algorithms were not exactly the same. If the count in the for loop (such as "numberOfMappings") was defined in a class (since it wasn't being defined in the function) then you wouldn't easily be able to determine what that for loop count would be. The variables such as "MappingItems" and "MappingNames" were also coming out of nowhere. So assuming all the above variables were variables defined elsewhere they would all be different and as such a template would not have been as sufficient a solution as it may have initially appeared.

As for a nearly identical algorithms being used multiple times being unoptimal, I would disagree. With only 3 differing types I don't feel a template is worth the problems it brings about. It's just my opinion, of course, but I feel that a template should be a tool you put a lot of consideration into before using; that you either need to account for many types, unknown types, or that you are 100% certain that none of the individual functions being combined into a template will ever need to be modified separate from eachother.
Topic archived. No new replies allowed.
Pages: 12