カスタム・ディターターを持つ一意のポインターを持つラッパー・クラスを作成しようとしています。これはクラスです:C++カスタム・ディターター・エラーの一意のポインター
class WindowObj
{
public:
WindowObj();
WindowObj(const WindowObj&) = delete;
WindowObj& operator=(const WindowObj&) = delete;
WindowObj(WindowObj&&);
WindowObj& operator=(WindowObj&&);
WindowObj(const char* title,int x,int y,const int& w,const int& h,SDL_WindowFlags flags);
SDL_Window* get();
protected:
private:
std::unique_ptr<SDL_Window,decltype(&SDL_DestroyWindow)> window;
};
WindowObj::WindowObj(const char* title,int x,int y,const int& w,const int& h,SDL_WindowFlags flags)
{
window = make_resource(SDL_CreateWindow,SDL_DestroyWindow,title,x,y,w,h,flags);
}
SDL_Window* WindowObj::get(){
return window.get();
}
WindowObj::WindowObj(){
window = NULL;
}
WindowObj::WindowObj(WindowObj&& other){
std::swap(window,other.window);
}
WindowObj& WindowObj::operator=(WindowObj&& other){
std::swap(window,other.window);
}
問題は、私はこれをコンパイルしようとすると、私はエラーerror: static assertion failed: constructed with null function pointer deleter
を得るということです。代わりにshared_ptrを使用すると問題は解決しますが、ポインタを共有する必要はありません。どんな助け?
make_resource関数はhttps://eb2.co/blog/2014/04/c-plus-plus-14-and-sdl2-managing-resources/からです。 – Magnus