私が行った場合:
std::unique_ptr<AVFrame, AVFrameDeleter> avFrameUniquePtr(av_frame_alloc());
エラーは発生しません。それを観察する
av_frame_alloc()
戻り値 AVFrame*
しかし私がそうするなら
std::unique_ptr<AVFrame, AVFrameDeleter> avFrameUniquePtr = std::make_unique<AVFrame,AVFrameDeleter>(av_frame_alloc());
私は得る
no instance of overloaded function "std::make_unique" matches the argument list -- argument types are: (AVFrame *)
私にとっては大丈夫なはずです。何が起こっていますか?
何が起こっていますか?
残念ながら、std::make_unique
削除者の種類を指定することはできません。その2番目のテンプレートパラメータは、渡される引数のリストのタイプに使用されます。AVFrameDeleter
明示的に指定したためにコードが失敗しますが、合格するAVFrame*
と一致しません。
std::make_shared
(を持っているstd::allocate_shared
)とは異なりstd::make_unique
、アロケータ対応の対応物はありません。架空のallocate_uniqueはunique_ptr<T,D>
、アロケーターオブジェクトを含み、operator()でdestroyとdelocateの両方を呼び出す、返されるデリッタータイプDを発明するために必要になります。
一方、次のコードは機能します(期待したものではありません)。
// 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());
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加