0
class Feature{};

class IFat
{
   //init feature for IFat

   vector<Feature> vf;
};
class IThin
{
   //init feature for IThin
   vector<Feature> vf;
};

class ISlim
{
    //init feature for ISlim
    vector<Feature> vf;
};

void func(IFeature_Vector)
{
     //accessing vf depending on IFeature_Vector passed in
}

I would like to know if there is a nice neat way to make one func that can call each instance without having to call three times for each case. I'm sorry to say this that I know this is a jurasic problem but I just can't think up a good solution while I am so much crazy for it. I hope you understand my problem. I am thankful if you could help.

  • 4
    I don't understand your problem, you need to provide more info. – Seth Carnegie Aug 20 '11 at 02:40
  • 1
    We don't know what `// init feature for IWhatever` means, or what "nice neat way to make one func that can call each instance without having to call three times for each case" means. – Seth Carnegie Aug 20 '11 at 02:57
  • 3
    "call each instance" does not make any sense. Can you rephrase? – Eugene S Aug 20 '11 at 02:58
  • guys, it is so complicated? He don't wants to write three overloaded versions of `void func( ... )` – Thomas Berger Aug 20 '11 at 03:02
  • 1
    @Thomas I guess we mortals find it hard to understand someone who says things like "i think I am not sitting here chuckling my binary activities" – Seth Carnegie Aug 20 '11 at 03:10
  • @Seth don't know what he wanted to tell me with that sentence, but a look at the code was helpfull to understand. I'm trainer at work, so i have to guess every day: "What he want's?" ;) – Thomas Berger Aug 20 '11 at 03:16

1 Answers1

1

I think you should have a look at template programming in C++. Here is a good explanation: http://www.cplusplus.com/doc/tutorial/templates/

You could write something like

template<class T> void func(T myVector) { ... };
Thomas Berger
  • 1,860
  • 13
  • 26