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

时间:2017-04-22 07:44:51

标签: 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 {
        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)错误,请帮我解决,谢谢

如何使用myvector填充Myreturn.shared并传递给printmyinfo?

1 个答案:

答案 0 :(得分:0)

也许你想要这个。

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

同样纠正最后一行,printmyinfo()参数类型不匹配。