Özel bir işaretçi ile benzersiz bir işaretçi içeren bir sarmalayıcı sınıfı yapmaya çalışıyorum. Bu sınıftır:C++ Özel işaretçi hatasıyla benzersiz işaretçi
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);
}
sorun bu derlemeye çalıştığımda hata error: static assertion failed: constructed with null function pointer deleter
elde edilmesi. Bunun yerine bir shared_ptr kullanmak sorunu çözer, ancak işaretçiyi paylaşmaya gerek duymayabilirim. Herhangi bir yardım?
make_resource işlevi https://eb2.co/blog/2014/04/c-plus-plus-14-and-sdl2-managing-resources/ adresinden alınmıştır. – Magnus