自動メモリ管理の利点のために、私のgdi +オブジェクトにstd :: unique_ptrを使用しようとしています。このスタンダールGDI + CスタイルのコードでGDI +オブジェクトのstd :: make_unique
ルック:
Gdiplus::Graphics* graphics = Gdiplus::Graphics::FromImage(image);
graphics->DrawRectangle(/* parameters */); // Working
私は次のように私がのstd :: unique_ptrをを使用することができることを知っている:
std::unique_ptr<Gdiplus::Graphics> graphics(Gdiplus::Graphics::FromImage(image));
graphics->DrawRectangle(/* parameters */); // Working
は今、私はSTDを構築したい:: unique_ptrとstd :: make_uniqueをコンパイルすることはできません。
私は次のことを試してみました:
std::unique_ptr<Gdiplus::Graphics> graphics = std::make_unique<Gdiplus::Graphics>(Gdiplus::Graphics::FromImage(image));
graphics->DrawRectangle(/* parameters */); // Not working
をしかし、私は、次の変換エラーを取得:「HDC」の「のGdiPlus ::グラフィックス」から1つの引数の C2664変換はできません。
私はVS2015の最新バージョンを使用しています。
私はSTDを考え:: make_uniqueそれはこのように使用する必要があります。
std::unique_ptr<T> varName = std::make_unique<T>(argument with which an instance of T will be constructed);
私が間違って何をしているのですか?
のように 'FromImage'が' Graphics'オブジェクトのメモリを割り当てていると思います。 – gurka
もう一つの注意:割り当てられた 'Graphics'オブジェクトが' delete'を使って割り当て解除されていることを確認してください。 'delete graphics;'。そうでなければ 'unique_ptr'にカスタムディレターを使う必要があります。 – gurka