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
}
我想知道是否有一个很好的方法来制作一个可以调用每个实例的func,而不必为每个案例调用三次。我很遗憾地说这是我知道这是一个jurasic问题,但我真的想不起一个好的解决方案,而我却为此疯狂。我希望你理解我的问题。如果你能提供帮助,我很感激。
答案 0 :(得分:1)
我认为你应该看一下C ++中的template
编程。这是一个很好的解释:http://www.cplusplus.com/doc/tutorial/templates/
你可以写点像
template<class T> void func(T myVector) { ... };