c – std :: unique_ptr和指针指针
发布时间:2020-12-16 10:09:58 所属栏目:百科 来源:网络整理
导读:我想将std :: unique_ptr与Free Image的FITAG结合使用.普通C中的代码是: ... load image;FITAG* tag = NULL;FreeImage_GetMetadata(FIMD_EXIF_EXIF,bitmap,"Property",tag);... do some stuff with tag;FreeImage_DeleteTag(tag);... delete image; 我对uni
我想将std :: unique_ptr与Free
Image的FITAG结合使用.普通C中的代码是:
... load image; FITAG* tag = NULL; FreeImage_GetMetadata(FIMD_EXIF_EXIF,bitmap,"Property",&tag); ... do some stuff with tag; FreeImage_DeleteTag(tag); ... delete image; 我对unique_ptr的尝试: std::unique_ptr<FITAG,void(*)(FITAG*)> tag(NULL,&FreeImage_DeleteTag); FreeImage_GetMetadata(FIMD_EXIF_EXIF,&tag.get()); 这明显回归: cannot take the address of an rvalue of type 'pointer' (aka 'FITAG *') 我该如何解决这个问题? 非常感谢提前. 解决方法
颠倒操作顺序;首先获取资源,然后构造unique_ptr.
FITAG *p = NULL; FreeImage_GetMetadata(FIMD_EXIF_EXIF,&p); std::unique_ptr<FITAG,void(*)(FITAG*)> tag(p,&FreeImage_DeleteTag); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |