Unique pointer assignment operator

Just started learning about smart pointers and my professor uses the assignmet operator like this in the slides.
1
2
  unique_ptr<double> p{};
  p = new double{5.0};


But this gives compilation error: No match for ‘operator=’ (operand types are ‘std::unique_ptr<double>’ and ‘double*’)

What am I missing?
Thanks! I also found this method. Is there a difference between these two ways of assigning:
1
2
    p = make_unique<double>(5.0);
    p = unique_ptr<double>(new double{5.0});
Last edited on
Topic archived. No new replies allowed.