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
}
我想知道是否有一种很好的方法可以使一个函数可以调用每个实例,而不必为每种情况调用三次。很遗憾地说,我知道这是一个侏罗纪问题,但是当我为之疯狂时,我只是想不出一个好的解决方案。希望你能理解我的问题。感谢您的帮助。
最佳答案
我认为您应该看看C ++中的template
编程。这是一个很好的解释:http://www.cplusplus.com/doc/tutorial/templates/
你可以写类似
template<class T> void func(T myVector) { ... };