2013-05-14 80 views
0

我玩弄一些提升容器,但最近,我封鎖,因爲我似乎無法multi_index_container的正確定義。我下面的一個例子,我下線抓住,但它仍然給了我和錯誤消息:故障定義的multi_index_container ordered_non_unique

struct boost::multi_index::global_fun<const node&, int, <error-constant>> 

Error: Expression must have a constant value 

這裏是我的聲明:

#define _CRT_SECURE_NO_DEPRECATE 
#define _SCL_SECURE_NO_DEPRECATE 
#include <boost/config.hpp> 

#include <string> 
#include <iostream> 

#include <boost/multi_index_container.hpp> 
#include <boost/multi_index/key_extractors.hpp> 
#include <boost/multi_index/hashed_index.hpp> 
#include <boost/multi_index/global_fun.hpp> 
#include <boost/multi_index/ordered_index.hpp> 
using namespace boost::multi_index; 

struct node 
{ 
    node(std::string da, int in) { 
     data = da; 
     numerical = in; 
    }; 
    std::string data; 
    int numerical; 
}; 

int main() 
{ 
    typedef multi_index_container< 
     node, 
     indexed_by< 
      hashed_unique< 
       member<node,std::string, &node::data>>, 
      ordered_non_unique< 
       global_fun<const node&, int, node::numerical>> //right here, the value numerical errors 
      > 
     > node_type; 



} 

我有一種預感,我不包括文件這,但我找不到解決方案。

+0

'node :: numerical'顯然不是一個全局函數,而是一個成員。你在想什麼? – pmr 2013-05-14 14:14:44

回答

1

這應做到:

typedef multi_index_container< 
    node, 
    indexed_by< hashed_unique< member<node,std::string, &node::data> > 
      , ordered_non_unique< member<node, int, &node::numerical> > 
      > 
    > node_type; 

global_fun預期,以及,一個gloabl功能。 &node::numerical是一個類似&node::data的會員。你當然可以編寫一個接受節點並提取它的函數,但你爲什麼要這麼做呢?

您還缺少member.hpp包括。

+0

哦,我現在明白了。我精明的思想認爲腿是他們結構的一員,並試圖打電話給我的成員。感謝幫助! – 2013-05-14 14:28:56