What to eat tonight
What to eat tonight

Reputation: 31

Design problem- one function calls all three

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.

Upvotes: 0

Views: 108

Answers (1)

Thomas Berger
Thomas Berger

Reputation: 1870

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) { ... };

Upvotes: 1

Related Questions