[英]void pointer to vector of boost shared pointer
i have a void pointer 我有一个空指针
void *vp;
I want to point it to vec_A
inside a function where vec_A
is passed as a reference, that is 我想将其指向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
}
and after I point vp
to vec_A
, how to I get it back as 在将vp
指向vec_A
,如何将其恢复为
std::vector<boost::shared_ptr<A> >
Address-of and cast: 地址和演员:
void * vp = &vec_A; // address-of
std::vector< boost::shared_ptr<A> > & v =
*static_cast< std::vector< boost::shared_ptr<A> >* >(vp);
Now v
is a reference to the very same vector whose address you took in the line above. 现在v
是对相同向量的引用,您在上一行中使用了其地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.