开发者

Do Boost MultiIndex Containers work with inherited class members?

开发者 https://www.devze.com 2023-02-10 01:25 出处:网络
I would like to use boost\'s multi-index container with a class hierarchy. Is this possible? If I try:

I would like to use boost's multi-index container with a class hierarchy. Is this possible?

If I try:

#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;
}

I get the following errors:

multiindextest.cpp:25: error: could not convert template argument ‘&A::m’ to ‘int B::*’
multiindextest.cpp:25: error: template argument 1 is invalid
multiindextest.cpp:26: error: template argument 2 is invalid
multiindextest.cpp开发者_如何学运维:27: error: template argument 2 is invalid
multiindextest.cpp:27: error: invalid type in declaration before ‘;’ token

If I change line 25 to:

ordered_non_unique<member<B, int, &B::n> >

It compiles fine. Any help would be much appreciated. Thanks.


I'm not quite sure, if this is what you are looking for, but you can change line 25 to:

ordered_non_unique<member<A, int, &A::m> >

This is compiling on gcc 4.4.

Regards Lars.

0

精彩评论

暂无评论...
验证码 换一张
取 消