I was getting confused with the usage of "new" in case of shared_ptr.
(1)shared_ptr<int>sharedPointer(new int (7));
This one works fine.
sharedPointer = new int (7);
As of my current understanding in both the scenarios new is returning a pointer of int type .
In the 2nd Line ,its throwing an error of no match for operator= (operand types are std::shared_ptr<int>' and int * );
Since "new" in this case is returning an int * why this error when assignment operator comes to picture ?
Can anybody explain ,the difference in both the cases ?
Case (2) shared_ptr<int>sharedPointer; sharedPointer = new int (7);
Default construction followed by assignment. ergo, looks for an overloaded assignment operator. http://en.cppreference.com/w/cpp/memory/shared_ptr/operator%3D
Error, no overloaded assignment operator which can accept a raw pointer as the operand on the rhs.