1

I am having an issue with make_unique that I am at a loss with.

_replace_find = unique_ptr<Fl_Input>(new Fl_Input{ 80, 10, 210, 25, "Find:" });
_replace_find = make_unique<Fl_Input>(Fl_Input{ 80, 10, 210, 25, "Find:" });

when I use the make_unique line it gives me this error, but when I use the other it compiles just fine. From my understanding make_unique pretty much does the same thing, but is exception safe.

Error   1   error C2248: 'Fl_Widget::Fl_Widget' : cannot access private member declared in class 'Fl_Widget'    c:\program files (x86)\microsoft visual studio 12.0\vc\include\fl\fl_input_.h   488 1   hayley

I couldn't find anything with that error dealing with make_unique or unique_ptr on SO. I wouldn't be asking this otherwise.

as always thank you for your time and advice.

Kijewski
  • 25,517
  • 12
  • 101
  • 143
Jason Ball
  • 163
  • 8

2 Answers2

6

You probably wanted to write

std::make_unique<FlInput>(80, 10, 210, 25, "Find:")

instead of

std::make_unique<FlInput>(FlInput{80, 10, 210, 25, "Find:"})

It seems the class FlInput has a private copy and/or move constructor making the second form illegal.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
5
_replace_find = unique_ptr<Fl_Input>(new Fl_Input{ 80, 10, 210, 25, "Find:" });
_replace_find = make_unique<Fl_Input>(Fl_Input{ 80, 10, 210, 25, "Find:" });

Those lines are not equivalent.

The first line creates an Fl_input on the free store, and then initializes a unique_ptr with it.
The second creates a temporary Fl_input and calls make_unique<Fl_input> with it, which creates a new instance on the free store by calling the copy/move ctor (which is obviously inaccessible, thus the error).

What you wanted is giving all the ctor-arguments to make_unique<Fl_input>:

_replace_find = make_unique<Fl_Input>(80, 10, 210, 25, "Find:");
Deduplicator
  • 44,692
  • 7
  • 66
  • 118
  • Thank you! This was the issue. Since Dietmar answered just before you I marked his a the answer. I up voted your answer too as it was well explained. – Jason Ball Oct 26 '14 at 23:44