小编Elw*_*rdi的帖子

当一次只需要一种类型时,保持指向不同类型的指针的最佳方法是什么?

我处于一种情况,我需要一个指向未知类型对象的指针作为另一个类的成员。但是有效对象类型的列表在编译时是已知的。

说我有:

// 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)

c++ pointers void-pointers unions c++11

5
推荐指数
1
解决办法
143
查看次数

标签 统计

c++ ×1

c++11 ×1

pointers ×1

unions ×1

void-pointers ×1