大佬教程收集整理的这篇文章主要介绍了c – 由于抽象模板arg的实例化,boost :: lambda表达式无法编译.任何解释和/或解决方法?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
显然在boost :: lambda的内容中,以下示例导致尝试实例化抽象类AbstractFoo,并阻止lambda表达式编译.问题是我不知道它为什么试图实例化它所以我不能尝试解决它.
任何boost :: lambda专家都可以:
#include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> struct AbstractFoo { typedef boost::shared_ptr<AbstractFoo> Ptr; virtual int it() const = 0; }; struct Bar : public AbstractFoo { typedef boost::shared_ptr<Bar> Ptr; virtual int it() const { return 3; } }; typedef AbstractFoo Foo; // Comment this out //typedef Bar Foo; // and this in to make this example compilable int main() { namespace bll = boost::lambda; boost::function< bool (const Foo::Ptr &)> func; func = (bll::protect(bll::bind( &Foo::it,*bll::_1))(bll::_1) == 3); return 0; }
这无法编译(在gcc 4.4.3,boost 1_40上)有一个怪物模板错误,其重要部分似乎是:
error: cAnnot declare field ‘boost::tuples::cons<AbstractFoo,boost::tuples::null_type>::head’ to be of abstract type ‘AbstractFoo’ because the following virtual functions are pure within ‘AbstractFoo’: virtual int abstractFoo::it() const
#include <boost/lambda/bind.hpp> #include <boost/lambda/lambda.hpp> #include <boost/shared_ptr.hpp> #include <boost/function.hpp> #include <iostream> struct AbstractFoo { typedef boost::shared_ptr<AbstractFoo> Ptr; virtual int it() const = 0; }; struct Bar : public AbstractFoo { typedef boost::shared_ptr<Bar> Ptr; virtual int it() const { return 3; } }; typedef AbstractFoo Foo; // Comment this out //typedef Bar Foo; // and this in to make this example compilable int main() { namespace bll = boost::lambda; boost::function< bool ( const Foo * )> func; func = ( bll::protect( bll::bind( &Foo::it,bll::_1 ) )( bll::_1 ) == 3); //func = bll::bind( &Foo::it,bll::_1 ); Foo::Ptr p( new Bar ); std::cout << std::boolalpha << func( p.get() ) << std::endl; }
更准确地说,这个:
*bll::_1
需要实例化和复制AbstractFoo类型的对象
以上是大佬教程为你收集整理的c – 由于抽象模板arg的实例化,boost :: lambda表达式无法编译.任何解释和/或解决方法?全部内容,希望文章能够帮你解决c – 由于抽象模板arg的实例化,boost :: lambda表达式无法编译.任何解释和/或解决方法?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。