Boost练习程序(智能指针)

#include <iostream> #include <vector> #include <string> #include <boost/shared_ptr.hpp> class A {
          
   public:     A(std::string s){a=s;}     std::string a; void print(){std::cout<<a<<
;} }; void main() {
          
       boost::shared_ptr<A> p1(new A("2345"));     boost::shared_ptr<A> p2(new A("dfgds"));     std::vector< boost::shared_ptr<A> > m;     std::vector< boost::shared_ptr<A> >::iterator it;     m.push_back(p1);     m.push_back(p2); for (it=m.begin();it!=m.end();it++)     {
          
           (*it)->print();     } }
#include #include #include #include class A { public: A(std::string s){a=s;} std::string a; void print(){std::cout< p1(new A("2345")); boost::shared_ptr p2(new A("dfgds")); std::vector< boost::shared_ptr > m; std::vector< boost::shared_ptr >::iterator it; m.push_back(p1); m.push_back(p2); for (it=m.begin();it!=m.end();it++) { (*it)->print(); } }
#include #include #include #include class A { public: A(std::string s){a=s;} std::string a; void print(){std::cout< p1(new A("2345")); boost::shared_ptr p2(new A("dfgds")); std::vector< boost::shared_ptr > m; std::vector< boost::shared_ptr >::iterator it; m.push_back(p1); m.push_back(p2); for (it=m.begin();it!=m.end();it++) { (*it)->print(); } }
经验分享 程序员 微信小程序 职场和发展