admin管理员组文章数量:1573011
解决方式
报错相关类,或者使用相关类作为类成员函数的类析构函数需要使用 default 关键字。
问题说明
在编译代码时,遇到了 error: invalid application of ‘sizeof’ to incomplete type “mlir::Pass” 的问题,因为相关代码与 std::unique_ptr 相关,遇到这一问题主要是 mlir::Pass
报错的这个类:
std::unique_ptr<mlir::Pass> xxxxx;
官方关于 std::unique_ptr 有相关说明:
std::unique_ptr may be constructed for an incomplete type T, such as to facilitate the use as a handle in the Pimpl idiom. If the default deleter is used, T must be complete at the point in code where the deleter is invoked, which happens in the destructor, move assignment operator, and reset member function of std::unique_ptr. (Conversely, std::shared_ptr can’t be constructed from a raw pointer to incomplete type, but can be destroyed where T is incomplete).
所以如果是直接创建的 mlir::Pass 对象,并且这个类的完整定义在其他的头文件,那么解决方法就是找到我们需要调用的类的完整定义的头文件,并包含进来即可。
如果是自己写的代码,并且作为类的成员则需要对定义类的析构函数设置为 default:
Demo::~Demo() = default;
主要参考:https://stackoverflow/questions/34072862/why-is-error-invalid-application-of-sizeof-to-an-incomplete-type-using-uniqu
http://blog.linluxiang.info/2015/03/13/pimpl_research/
上面包含头文件的方式,其实相关类的完整定义里面也能看到 virtual ~Pass() = default;
的定义。
本文标签: applicationInvalidErrorsizeofXXXXX
版权声明:本文标题:error: invalid application of ‘sizeof‘ to incomplete type “xxxxx“ 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1726220423a1061041.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论