C++ 将向量对象存储在共享指针抛出错误中?

C++ 将向量对象存储在共享指针抛出错误中?,c++,vector,shared-ptr,C++,Vector,Shared Ptr,您好,我正在存储一个向量对象,它是共享指针,并调用一个打印进程来打印它,但它会抛出一个错误,“与调用**不匹配”下面是代码 namespace info { typedef struct { std::string Yes; std::string NO; int ID_NO; } mystruct; typedef std::vector<mystruct> myvector; typedef struct {

您好,我正在存储一个向量对象,它是共享指针,并调用一个打印进程来打印它,但它会抛出一个错误,“与调用**不匹配”下面是代码

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
名称空间信息
{
类型定义结构{
std::字符串是;
std::字符串编号;
国际识别号;
}我的结构;
typedef std::vector myvector;
类型定义结构{
布尔状态;
std::shared\u ptr shared;
}我的回报;
}
void printmyinfo(const std::shared_ptr&printval)
{
如果(printval==NULL)
{
也许你想要这个

returnobj.shared = shared_ptr<info::myvector>(&structinfo) // 
returnobj.shared=shared\u ptr(&structinfo)//

还要更正最后一行,您的
printmyinfo()
参数类型不匹配。

很抱歉,它在堆上而不是堆栈上。我需要在Myreturn结构下面使用共享指针来存储向量对象typedef结构{bool status;std::shared_ptr shared;}Myreturn;指向堆栈分配对象的共享指针根本没有用处。