【问题标题】:How can i inherit from all types in mpl::vector?我如何从 mpl::vector 中的所有类型继承?
【发布时间】:2015-05-29 09:34:03
【问题描述】:

我使用 boost 1.58 中的mpl::vector。我有类型:

typedef mpl::vector <base1, base2, base3> types;

如果我有一个类派生,我如何从mpl::vector 中的所有这些类型继承它?

【问题讨论】:

    标签: c++ boost metaprogramming multiple-inheritance


    【解决方案1】:

    您可以使用inherit_linearly

    使用示例:

    class A 
    {
    public:
       void a() {}
    };
    class B 
    {
    public:
       void b() {}
    };
    class C 
    {
    public:
       void c() {}
    };
    
    typedef boost::mpl::vector<A, B, C> types;
    
    
    class Derived :
    public boost::mpl::inherit_linearly<types, 
    boost::mpl::inherit<boost::mpl::_1, boost::mpl::_2> >::type
    {
    };
    
    int main()
    {
       Derived d;
       d.a();
       d.b();
       d.c();
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多