我有一个无效指针
void *vp;
我想在vec_A
作为参考传递的函数中指向vec_A
,即
some_function(std::vector<boost::shared_ptr<A> >& vec_A)
{
void *vp;
//now i want vp to point to vec_A
}
在我将vp
指向vec_A
后,如何将其恢复为
std::vector<boost::shared_ptr<A> >
答案 0 :(得分:5)
地址和演员:
void * vp = &vec_A; // address-of
std::vector< boost::shared_ptr<A> > & v =
*static_cast< std::vector< boost::shared_ptr<A> >* >(vp);
现在v
是对同一个向量的引用,该向量的地址在上面的行中。