Templates Boost多索引容器是否与继承的类成员一起工作?

Templates Boost多索引容器是否与继承的类成员一起工作?,templates,inheritance,boost,g++,containers,Templates,Inheritance,Boost,G++,Containers,我想将boost的多索引容器与类层次结构结合使用。这可能吗 如果我尝试: #include <boost/multi_index_container.hpp> #include <boost/multi_index/ordered_index.hpp> #include <boost/multi_index/identity.hpp> #include <boost/multi_index/member.hpp> using namespace

我想将boost的多索引容器与类层次结构结合使用。这可能吗

如果我尝试:

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/identity.hpp>
#include <boost/multi_index/member.hpp>

using namespace ::boost;
using namespace ::boost::multi_index;

class A{
    public:
        int m;
        A(int p = 0){m = p;};
};

class B: public A{
    public:
        int n;
        B(int p = 0, int q = 0): A(p){ n = q;};
 }; 


typedef multi_index_container<
    B,
    indexed_by<
        ordered_unique<identity<B> >,
        ordered_non_unique<member<B, int, &B::m> >
    > 
> mindex;

int main(void){
    return 0;
}
如果我将第25行更改为:

ordered_non_unique<member<B, int, &B::n> >
ordered_non_unique<member<A, int, &A::m> >
有序非唯一

它编译得很好。任何帮助都将不胜感激。谢谢。

我不太确定,如果这是您要找的,但您可以将第25行更改为:

ordered_non_unique<member<B, int, &B::n> >
ordered_non_unique<member<A, int, &A::m> >
有序非唯一
这是在GCC4.4上编译的

向拉尔斯问好