Diff btw boost::shared_ptr and boost::makesha

Help
Johnacandy
2010-10-07
2013-05-14
  • Johnacandy
    Johnacandy
    2010-10-07

    I know what boost::shared_ptr does… but boost::make_share came up what does that do.
    Here is the code for boost::shared_ptr which shows my extend of knowledge…

    #include <iostream>
    #include <boost/shared_ptr.hpp>
    class Student
    {
    private:
        std::string m_sName;
    
        std::string m_sId;
    public:
        Student(std::string sName, std::string sId);
    
        ~Student();
        std::string getName() const;
        std::string getId() const;
    };
    Student::Student(std::string sName, std::string sId) : 
                            m_sName(sName), 
                            m_sId(sId)
    {
        //Everything has been init
    }
    Student::~Student()
    {
        //Nothing to do
        std::cout << "Elvis has left the building." << std::endl;
    }
    std::string Student::getName() const
    {
        return m_sName;
    }
    std::string Student::getId() const 
    {
        return m_sId;
    }
    typedef boost::shared_ptr<Student> StudentPtr;
    int main()
    {
        StudentPtr pStudent( new Student("Leon Anavi", "F010203") );
        std::cout << "Student: " << pStudent->getName() << " " 
            << pStudent->getId() << std::endl;
        return 0;
    }