+ Reply to Thread
Results 1 to 2 of 2

Thread: Simple use of make_shared

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    23

    Simple use of make_shared

    Can anybody know how to use of make_shared in new C++ standard? Please provide me simple example and use of it.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    27
    make_shared can be used to create a smart point. It allocates an object of the given type.

    Example:
    Code:
    class CEmployee
    {
    private:
    	int m_nID ;
    public:
    	CEmployee(int nID)
    	{
    		OutputDebugString("CEmployee::Constructor executes.\n") ;
    		m_nID = nID ;
    	}
    
    	~CEmployee()
    	{
    		OutputDebugString("CEmployee::Destructor executes.\n") ;
    	}
    
    	int GetEmployeeID()
    	{
    		return m_nID ;
    	}
    } ;
    
    void SimpleMakeSharedPtr()
    {
    	std::shared_ptr<CEmployee> sp = std::make_shared<CEmployee>(1) ;
    	int nID = sp->GetEmployeeID() ;
    }

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts