+ Reply to Thread
Results 1 to 2 of 2

Thread: compiler fails while allocating one unique_ptr to another

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    26

    compiler fails while allocating one unique_ptr to another

    Why below program fails?

    Code:
    class MyClass
    {
    public:
    	MyClass()
    	{
    		OutputDebugString("const::MyClass.\n") ;
    	}
    
    	~MyClass()
    	{
    		OutputDebugString("dest::MyClass.\n") ;
    	}
    } ;
    
    void USeUniquePtr()
    {
    	std::unique_ptr<MyClass> up(new MyClass()) ;
    
    	std::unique_ptr<CValue> up2 = up ;//Compile time Error, why?
    }
    What is the reason?

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    24
    This is because 'unique+ptr" says you cannot allocate one unique_ptr to another. This is by definition.

+ 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