Unique pointer assignment operator

Mar 24, 2022 at 9:10pm
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?
Mar 24, 2022 at 9:22pm
Mar 24, 2022 at 9:40pm
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 Mar 24, 2022 at 9:41pm
Mar 25, 2022 at 9:42am
Topic archived. No new replies allowed.