我处于一种情况,我需要一个指向未知类型对象的指针作为另一个类的成员。但是有效对象类型的列表在编译时是已知的。
说我有:
// A class templated on T
template<class T> class obj;
// Now assume there are some objects of types obj<...> somewhere else
obj<int> obj1;
obj<double> obj2;
// Now, manager needs to create a pointer for these objects
// in a specific manner at construction-time
// Say, we have to choose a canonical object (and set the other as secondary)
// manager shouldn't be templated on T because It needs
// to have multiple members of type obj<...>
template<class …Run Code Online (Sandbox Code Playgroud)