将共享指针存储矢量对象抛出错误?
喜IM存储一个矢量对象共享指针和调用打印过程打印出来,但它抛出一个错误,因为“敌不过呼叫**”下面是代码将共享指针存储矢量对象抛出错误?
namespace info
{
typedef struct {
std::string Yes;
std::string NO;
int ID_NO;
} mystruct;
typedef std::vector<mystruct> myvector;
typedef struct {
bool status;
std::shared_ptr<myvector> shared;
} Myreturn;
}
void printmyinfo(const std::shared_ptr<info::mystruct>& printval)
{
if(printval == NULL)
{
cout<<"Sorry no value exist"<<endl;
return;
}
// here is print code which is good.
}
int main()
{
info::mystruct *structinfo=new mystruct ;
structinfo->yes="okay";
structinfo->ID_NO=10;
info::myvector vectorobject;
vectorobject.push_back(structinfo);
info::Myreturn *returnobj=new Myreturn;
returnobj->shared(myvector)// bad how to store vector in share pointer of Myreturn structure
//如何用myvector填充Myreturn.shared并传递给printmyinfo? printmyinfo(myvector)//坏 }
在这一行returnobj.shared(structinfo)
错误thow请帮我解决它感谢
如何填写Myreturn.shared与myvector,并传递给printmyinfo?
也许你想要这个。
returnobj.shared = shared_ptr<info::myvector>(&structinfo) //
还纠正最后一行,您的printmyinfo()
参数类型不匹配。
我需要使用下面Myreturn结构共享指针存储vectorobject typedef结构{ BOOL状态; 的std :: shared_ptr的
共享指针堆栈分配的对象是没有作用的。 –
对不起我的错误是在堆不是堆叠。 – pravakar