【发布时间】:2015-08-02 15:20:31
【问题描述】:
我已经决定厌倦了决定哪些类负责删除哪些位图。我试图重写我的代码以使用带有自定义删除器的智能指针al_destroy_bitmap
我的代码很简单。
shared_ptr<ALLEGRO_BITMAP> test = make_shared<ALLEGRO_BITMAP>(al_load_bitmap("hello.png"), al_destroy_bitmap);
我遇到了很多我似乎无法解决的错误。
error C2079: 'std::_Get_align<ALLEGRO_BITMAP>::Elt2' uses undefined struct 'ALLEGRO_BITMAP'
error C2079: 'std::_Get_align<ALLEGRO_BITMAP>::Elt0' uses undefined struct 'ALLEGRO_BITMAP'
error C2027: use of undefined type 'ALLEGRO_BITMAP'
error C2027: use of undefined type 'ALLEGRO_BITMAP'
解决我的问题的其他解决方案是创建一个 Bitmap 类来包装 Allegro 的所有内容,但这看起来很难看,我认为我不应该这样做。另外,我已经在各处使用了其他 allegro 函数,然后我想为ALLEGRO_SAMPLE 和ALLEGRO_FONT 编写相同类型的类。我真的不想这样做。
如何在 Allegro 位图中使用智能指针?
编辑:也许是为了让非 Allegro 编码人员了解 ALLEGRO_BITMAP 的工作原理,我将在下面发布一些代码
ALLEGRO_BITMAP *test = al_load_bitmap("hello.png") // This works
ALLEGRO_BITMAP test1; // This fails with error C2079 undefined struct ALLEGRO_BITMAP. I expect this here.
【问题讨论】:
标签: c++ smart-pointers allegro allegro5