我正在编写一个具有向量作为私有属性的类.向量的类型(可以是TBB库中的concurrent_vector或std向量)仅在运行时已知,具体取决于用户指定的参数.
所以问题是,我该如何编码呢?我想的是:
class A {
private:
void* vec;
public:
A( int type ) {
if ( type == 1 ) {
// convert the void* into std::vector<>
} else {
// convert into a tbb::concurrent_vector
}
}
};
那个转换,可以通过reinterpret_cast来完成吗?或者还有另一种更好的方法吗?
我在空白.谢谢你的时间.
c++ ×1