【发布时间】:2015-09-01 12:49:20
【问题描述】:
最近,我尝试使用带有前向声明类型的 boost.type_erasure,如下所示:
#include <boost/type_erasure/any.hpp>
#include <boost/type_erasure/member.hpp>
struct Type;
BOOST_TYPE_ERASURE_MEMBER((HasTest), Test, 1)
using Any = boost::type_erasure::any <
boost::mpl::vector <
HasTest<void(Type&)>,
boost::type_erasure::destructible<>,
boost::type_erasure::relaxed
>
>;
int main() {
Any obj;
}
但是,编译器(例如 clang)抱怨类型不完整:
/usr/local/include/boost/type_traits/is_base_and_derived.hpp:228:42: error: incomplete type 'Type' used in type trait expression
BOOST_STATIC_CONSTANT(bool, value = (BOOST_IS_BASE_OF(B,D) && ! ::boost::is_same<ncvB,ncvD>::value));
最后,我必须通过将 API 从引用更改为指针来解决问题,即将 Type& 替换为 Type*。
问题:
上面的代码可以运行吗?
【问题讨论】:
标签: c++ boost boost-type-erasure