Hi Guys,

Say I have a function with just a single parameter. Is it possible to call a particular object based on that param? i.e. I have 2 different classes ClassA and ClassB. If param = 1, I call ClassA.doSomething if param = 2, i call ClassB.doSomething. Note, that both the classes have the same function name but each one does this same taskdifferently and achieves a different result.

The only solution I can think of would use cases or if and else:

Qt Code:
  1. Function(iParam)
  2. {
  3. if(iParam == 1)
  4. {
  5. ClassA.doSomething;
  6. }
  7. else if(iParam ==2)
  8. {
  9. ClassB.doSomething;
  10. }
  11. }
To copy to clipboard, switch view to plain text mode 

I obviously want to steer away from having 100 if and else statements. The main problem I have with this is the fact that I'll be creating an instance on the heap of only 1 of these classes, and I just need to access an objects function based on which one is loaded on the heap.