Boost MultiIndex 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;
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;
}
我收到以下错误:
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
如果我将第 25 行更改为:
ordered_non_unique<member<B, int, &B::n> >
它可以正常编译。任何帮助将不胜感激。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太确定,这是否是您正在寻找的内容,但您可以将第 25 行更改为:
This is compiling on gcc 4.4。
问候拉尔斯。
I'm not quite sure, if this is what you are looking for, but you can change line 25 to:
This is compiling on gcc 4.4.
Regards Lars.