Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/139.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boost::multi_索引的问题_C++_Boost_Multi Index_Boost Multi Index - Fatal编程技术网

C++ boost::multi_索引的问题

C++ boost::multi_索引的问题,c++,boost,multi-index,boost-multi-index,C++,Boost,Multi Index,Boost Multi Index,当我尝试创建此对象时 typedef boost::multi_index_container< ClassX*, //mapped value boost::multi_index::indexed_by< //list o

当我尝试创建此对象时

typedef boost::multi_index_container<
ClassX*,                                                                                    //mapped value
boost::multi_index::indexed_by<                                                 //list of indices    
    boost::multi_index::hashed_unique<                                                          
        boost::multi_index::const_mem_fun<ParentClassOfX, Key1, &ParentClassOfX::getKey1>               //hashed index by unique Key1
    >,
    boost::multi_index::hashed_unique<           
        boost::multi_index::const_mem_fun<ParentClassOfX, Vs64, &ParentClassOfX::getKey2>               //hashed index by unique Key1
    >
>
>ClassXMultiKeyIndexed;
然后像这样插入一个指针

ClassX *a;
ClassXMultiKeyIndexed sample;

//a is not NULL and is filled up before the below insert
sample.insert(a);
这是编译错误,如果“sample.insert(a)”被注释掉,它可以编译

编译错误:

Compiling...
.
.
.
xtyab.cpp
c:\code\common\lib\boost\boost\detail\allocator_utilities.hpp(153) : error     C2061: syntax error : identifier 'p'
            c:\code\common\lib\boost\boost\multi_index\detail\index_base.hpp(105) : see     reference to function template instantiation 'void boost::detail::allocator::construct<Container*>(void *,const Type &)' being compiled
    with
    [
        Type=Container *
    ]
    c:\code\common\lib\boost\boost\multi_index\detail\index_base.hpp(102) : while compiling class template member function 'boost::multi_index::detail::hashed_index_node<Super,Category> *boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>::insert_(Container *const &,boost::multi_index::detail::hashed_index_node<Super,Category> *&,boost::multi_index::detail::lvalue_tag)'
    with
    [
        Super=boost::multi_index::detail::hashed_index_node<boost::multi_index::detail::index_node_base<Container *,std::allocator<Container *>>,boost::multi_index::detail::hashed_unique_tag>,
        Category=boost::multi_index::detail::hashed_unique_tag,
        Value=Container *,
        IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,
        Allocator=std::allocator<Container *>
    ]
    c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(93) : see reference to class template instantiation 'boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>' being compiled
    with
    [
        Value=Container *,
        IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,
        Allocator=std::allocator<Container *>
    ]
    c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(93) : see reference to class template instantiation 'boost::multi_index::detail::hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>' being compiled
    with
    [
        KeyFromValue=boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>,
        Hash=boost::hash<boost::long_long_type>,
        Pred=std::equal_to<__int64>,
        SuperMeta=boost::multi_index::detail::nth_layer<2,Container *,boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,std::allocator<Container *>>,
        TagList=boost::mpl::vector0<boost::mpl::na>,
        Category=boost::multi_index::detail::hashed_unique_tag
    ]
    c:\code\common\lib\boost\boost\multi_index_container.hpp(100) : see reference to class template instantiation 'boost::multi_index::detail::hashed_index<KeyFromValue,Hash,Pred,SuperMeta,TagList,Category>' being compiled
    with
    [
        KeyFromValue=boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>,
        Hash=boost::hash<boost::long_long_type>,
        Pred=std::equal_to<__int64>,
        SuperMeta=boost::multi_index::detail::nth_layer<1,Container *,boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>,std::allocator<Container *>>,
        TagList=boost::mpl::vector0<boost::mpl::na>,
        Category=boost::multi_index::detail::hashed_unique_tag
    ]
    c:\code\common\src\biz\model\stm-stow_model\stm_container_manager_abc.h(323) : see reference to class template instantiation 'boost::multi_index::multi_index_container<Value,IndexSpecifierList>' being compiled
    with
    [
        Value=Container *,
        IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Key1,DBObject::getKey1>>,boost::multi_index::hashed_unique<boost::multi_index::const_mem_fun<DBObject,Vs64,DBObject::getKey2>>>
    ]
Build log was saved at "file://c:\code\win\Debug\obj\BuildLog.htm"
ProjABC - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
编译。。。
.
.
.
xtyab.cpp
c:\code\common\lib\boost\boost\detail\allocator\u utilities.hpp(153):错误C2061:语法错误:标识符“p”
c:\code\common\lib\boost\boost\multi\u index\detail\index\u base.hpp(105):请参阅正在编译的函数模板实例化“void boost::detail::allocator::construct(void*,const Type&)”的参考
具有
[
类型=容器*
]
c:\code\common\lib\boost\boost\multi_index\detail\index\u base.hpp(102):编译类模板成员函数'boost::multi_index::detail::hashed_index_node*boost::multi_index::detail::index_base::insert(容器*const&,boost::multi_index::detail::hashed_index_node*&,boost::multi_index::detail::lvalue_标记)'
具有
[
Super=boost::multi_index::detail::hash_index_节点,
Category=boost::multi_index::detail::hash_unique_标记,
值=容器*,
IndexSpecifierList=boost::multi_index::indexed_by,
分配器=std::分配器
]
c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(93):请参阅正在编译的类模板实例化“boost::multi_index::detail::index_base”的参考
具有
[
值=容器*,
IndexSpecifierList=boost::multi_index::indexed_by,
分配器=std::分配器
]
c:\code\common\lib\boost\boost\multi_index\hashed_index.hpp(93):请参阅正在编译的类模板实例化“boost::multi_index::detail::hashed_index”的参考
具有
[
KeyFromValue=boost::多索引::const\u mem\u fun,
Hash=boost::Hash,
Pred=std::等于,
SuperMeta=boost::多索引::细节::第n层,
TagList=boost::mpl::vector0,
Category=boost::multi_index::detail::hash_unique_标记
]
c:\code\common\lib\boost\boost\multi_index_container.hpp(100):请参阅正在编译的类模板实例化“boost::multi_index::detail::hash_index”的参考
具有
[
KeyFromValue=boost::多索引::const\u mem\u fun,
Hash=boost::Hash,
Pred=std::等于,
SuperMeta=boost::多索引::细节::第n层,
TagList=boost::mpl::vector0,
Category=boost::multi_index::detail::hash_unique_标记
]
c:\code\common\src\biz\model\stm-stow\u model\stm\u container\u manager\u abc.h(323):请参阅正在编译的类模板实例化“boost::multi\u index::multi\u index\u container”
具有
[
值=容器*,
IndexSpecifierList=boost::多索引::索引依据
]
生成日志保存在“file://c:\code\win\Debug\obj\BuildLog.htm”中
ProjABC-1个错误,0个警告
======生成:0成功,1失败,0最新,0跳过==========
编译器指向boost
谢谢

错误消息
c:\code\common\lib\boost\boost\detail\allocator\u utilities.hpp(153):错误C2061:语法错误:标识符“p”
暗示您可能无意中修改了boost源代码。

这不太可能是boost多索引容器的问题,您没有给出太多细节,但是下面的代码基于您的方法,应该可以很好地编译。在你的编译器上尝试一下——一旦你自己证明了这一点,然后比较不同之处并修复它

#include <iostream>

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>

using boost::multi_index_container;
using boost::multi_index::indexed_by;
using boost::multi_index::hashed_unique;
using boost::multi_index::tag;

using namespace std;

struct foo {
    int id_a;
    int id_b;
    int get_id_a() const {
        return id_a;
    }
    int get_id_b() const {
        return id_b;
    }
};

struct tag_a {};
struct tag_b {};

using foo_container = boost::multi_index_container<
foo*,
indexed_by<
  hashed_unique<tag<tag_a>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_a)>,
  hashed_unique<tag<tag_b>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_b)>
>
>;

int main() {
    foo_container c;
    foo f1{1, 2};
    foo f2{2, 3};
    c.insert(&f1);
    c.insert(&f2);

    {
        auto it = c.get<tag_a>().find(1);
        if (it != c.get<tag_a>().end()) {
            cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
        }
    }
    {
        auto it = c.get<tag_b>().find(3);
        if (it != c.get<tag_b>().end()) {
            cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
        }
    }    
}
#包括
#包括
#包括
#包括
#包括
使用boost::multi_index_容器;
使用boost::multi_index::index_by;
使用boost::multi_index::hash_unique;
使用boost::multi_index::tag;
使用名称空间std;
结构foo{
国际开发署;
国际开发银行;
int get_id_a()常量{
返回id_a;
}
int get_id_b()常量{
返回id_b;
}
};
结构标签a{};
结构标记_b{};
使用foo_container=boost::multi_index_container<
富*,
索引<
hash_unique,
哈希_唯一
>
>;
int main(){
富奥集装箱c;
foo f1{1,2};
foo f2{2,3};
c、 插入(&f1);
c、 插入(&f2);
{
autoit=c.get().find(1);
if(it!=c.get().end()){

无法识别请提供一个,而不是一个包含未知类的代码段。语法错误是您键入
p
,而编译器不知道它。@Ram可以肯定的是,只使用
\include
@MaximEgorushkin:编译一个空的源文件可能无法证明任何事情,因为模板在使用之前不会实例化。
#include <iostream>

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/hashed_index.hpp>
#include <boost/multi_index/mem_fun.hpp>

using boost::multi_index_container;
using boost::multi_index::indexed_by;
using boost::multi_index::hashed_unique;
using boost::multi_index::tag;

using namespace std;

struct foo {
    int id_a;
    int id_b;
    int get_id_a() const {
        return id_a;
    }
    int get_id_b() const {
        return id_b;
    }
};

struct tag_a {};
struct tag_b {};

using foo_container = boost::multi_index_container<
foo*,
indexed_by<
  hashed_unique<tag<tag_a>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_a)>,
  hashed_unique<tag<tag_b>, BOOST_MULTI_INDEX_CONST_MEM_FUN(foo, int, get_id_b)>
>
>;

int main() {
    foo_container c;
    foo f1{1, 2};
    foo f2{2, 3};
    c.insert(&f1);
    c.insert(&f2);

    {
        auto it = c.get<tag_a>().find(1);
        if (it != c.get<tag_a>().end()) {
            cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
        }
    }
    {
        auto it = c.get<tag_b>().find(3);
        if (it != c.get<tag_b>().end()) {
            cout << (*it)->id_a << ' ' << (*it)->id_b << endl;
        }
    }    
}