+ Reply to Thread
Results 1 to 2 of 2

Thread: What is auto_ptr?

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    46

    What is auto_ptr?

    What is auto_ptr?

    How to use it?

    Is there any other option available to auto_ptr?

    Is it safe to use auto_ptr in my application?

    Help.

  2. #2
    Junior Member
    Join Date
    Apr 2012
    Posts
    38
    std::auto_ptr is a smart pointer example.

    It can accept any use defined or integral type and can work on them.

    It provides -> operator as well.

    User will not to delete the type as std::auto_ptr deletes it implicitly in its destructor.

    Example:

    Code:
    class CStudent
    {
    private:
    	int m_nRoleID ;
    	std::string m_strName ;
    
    public:
    	CStudent(std::string strName, int nRoleID)
    	{
    		m_nRoleID = nRoleID ;
    		m_strName = strName ;
    	}
    
    	int GetRoleID()
    	{
    		return m_nRoleID ;
    	}
    
    	std::string GetName()
    	{
    		return m_strName ;
    	}
    
    } ;
    
    void UseAutoPtr()
    {
    	std::auto_ptr<CStudent> pStudent(new CStudent("Ruger", 1)) ;
    
    	int nRoleID = pStudent->GetRoleID() ;
    
    	std::string strName = pStudent->GetName() ;
    }

+ 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