With normal pointers, I can declare a pointer and then set it equal to a new object, however with shared pointers I am unable to do that. Why?
#include <memory>
struct node{
int num;
node* next;
};
int main()
{
std::shared_ptr<node> new_node1 = NULL; // WORKS
new_node1 = new node; // ERROR, why?
node* new_node2 = NULL; //WORKS
new_node2 = new node; //WORKS
return 0;
}
Why can't we create a new object for a shared pointer? Is there a way to do it?