no instance of overloaded function "std::make_unique" matches the argument list, but works with unique_ptr constructor

Guerlando OCs

If I do:

std::unique_ptr<AVFrame, AVFrameDeleter> avFrameUniquePtr(av_frame_alloc());

I get no errors. Observe that

av_frame_alloc() 

returns AVFrame*

However if I do

std::unique_ptr<AVFrame, AVFrameDeleter>  avFrameUniquePtr = std::make_unique<AVFrame,AVFrameDeleter>(av_frame_alloc());

I get

no instance of overloaded function "std::make_unique" matches the argument list -- argument types are: (AVFrame *)

For me it should be ok. What's happening?

songyuanyao

What's happening?

Unfortunately, std::make_unique can't specify the deleter type. Its 2nd template parameter is used for the type of the list of arguments passed to it. The code fails because you specify it as AVFrameDeleter explicitly, but pass AVFrame*, they don't match.

Unlike std::make_shared (which has std::allocate_shared), std::make_unique does not have an allocator-aware counterpart. A hypothetical allocate_unique would be required to invent the deleter type D for the unique_ptr<T,D> it returns which would contain an allocator object and invoke both destroy and deallocate in its operator().

On the other hand, the following code works (even it's not what you expect).

// the 1st template parameter is specified as AVFrame
// the 2nd template parameter is deduced as {AVFrame*}
// construct a std::unique_ptr<AVFrame, std::default_delete<AVFrame>>
std::make_unique<AVFrame>(av_frame_alloc()); 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

no instance of overloaded function "std::make_unique" matches the argument list

Can std::make_unique take the output of a function as an argument?

Why std::make_unique calls copy constructor

Using std::make_unique with the GetProfileBinary function call

Why does std::make_unique not require an argument in a default member initialisation if it is never called?

Way for class template to deduce type when constructing an instance with std::make_unique?

std::make_unique's (and emplace, emplace_back's) awkward deduction for initializer_list arguments

Is there a reason why std::make_shared/std::make_unique don't use list initialization?

Why I cannot pass std::make_unique<S> as a function parameter?

Template for std::make_unique<int[]> with initializer

std::make_unique, anonymous namespace and ODR

Assignment using std::make_unique<>

Custom initialize array with std::make_unique

std::make_unique with placement new

No instance of overloaded function matches the argument list

Can std::make_unique be used with abstract interface?

R-value references and std::make_unique

C++ Smart Pointer Lost in std::make_unique

How to make std::make_unique a friend of my class

push_back or emplace_back with std::make_unique

Trouble using std::make_unique with member variable of class

Why use std::make_unique in C++17?

Valgrind shows memory leak in std::make_unique

How to use a custom deleter using WinAPI with std::make_unique?

Advantages of using std::make_unique over new operator

new T(...) vs. std::make_unique<T>(...).release()

C2661 when using std::make_unique

How does returning std::make_unique<SubClass> work?

Using std::make_unique with custom deleter on a derived class?

TOP Ranking

  1. 1

    pump.io port in URL

  2. 2

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  5. 5

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  6. 6

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  7. 7

    mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (111 Connection refused)

  8. 8

    What's the point of declaring a const in JavaScript

  9. 9

    The prefix "andriod" for attribute "andriod:name" associated with an element type "application" is not bound?

  10. 10

    Change both state and params dynamically in ui-sref

  11. 11

    Copying a slide from one Google Slides presentation into another

  12. 12

    Grails with Oracle thick OCI driver authenticate to Oracle with wrong user

  13. 13

    Converting a class method to a property with a backing field

  14. 14

    How to use Angular2 and Typescript in Jsfiddle

  15. 15

    clojure.lang.LazySeq cannot be cast to class clojure.lang.Associative

  16. 16

    Inner Loop design for webscrapping

  17. 17

    How to set tab order for array of cluster,where cluster elements have different data types in LabVIEW?

  18. 18

    Removed zsh, but forgot to change shell back to bash, and now Ubuntu crashes (wsl)

  19. 19

    IServiceCollection does not contain a defintion for AddHttpClient

  20. 20

    What's the difference between conflict and compulsory cache miss?

  21. 21

    How to run blender on webserver?

HotTag

Archive