Example to use shared_ptr?

后端 未结 7 1307
孤城傲影
孤城傲影 2020-12-02 05:08

Hi I asked a question today about How to insert different types of objects in the same vector array and my code in that question was

 gate* G[1000];
G[0] =         


        
相关标签:
7条回答
  • Through Boost you can do it >

    std::vector<boost::any> vecobj;
        boost::shared_ptr<string> sharedString1(new string("abcdxyz!"));    
        boost::shared_ptr<int> sharedint1(new int(10));
        vecobj.push_back(sharedString1);
        vecobj.push_back(sharedint1);
    

    > for inserting different object type in your vector container. while for accessing you have to use any_cast, which works like dynamic_cast, hopes it will work for your need.

    0 讨论(0)
提交回复
热议问题