开发者

Design problem- one function calls all three

开发者 https://www.devze.com 2023-03-29 04:42 出处:网络
class Feature{}; class IFat { //init feature for IFat vector<Feature> vf; }; class IThin { //init feature for IThin
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 s开发者_运维百科ay 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.


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

精彩评论

暂无评论...
验证码 换一张
取 消