简体   繁体   English

在共享指针中存储矢量对象会抛出错误?

[英]Storing vector object in shared pointer throw error?

Hi im Storing a vector object is shared pointer and calling a print process to print it but its throw an error as " no match for call to **" Below is the code 嗨,即时通讯,存储矢量对象是共享的指针,并调用打印过程进行打印,但是它会抛出错误,如“对**的调用不匹配”,下面是代码

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

// how to fill Myreturn.shared with myvector and pass to printmyinfo? //如何用myvector填充Myreturn.shared并传递给printmyinfo? printmyinfo(myvector)//bad } printmyinfo(myvector)//坏}

At this line returnobj.shared(structinfo) error is thow please help me to fix it thanks 在此行returnobj.shared(structinfo)错误,请帮助我修复它,谢谢

how to fill Myreturn.shared with myvector and pass to printmyinfo? 如何用myvector填充Myreturn.shared并传递给printmyinfo?

Maybe you want this. 也许你想要这个。

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

Also correct the last line, your printmyinfo() argument type does not match. 同时更正最后一行,您的printmyinfo()参数类型不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM