2013-05-14 6 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 :: numeric'은 명백히 전역 함수가 아니라 멤버입니다. 너 뭐하니? – pmr

답변

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

오, 이제 알겠습니다. 나의 화려한 생각은 다리가 구조의 일원이었고, 나의 회원에게 전화하려고했다. 도움을 감사하십시오! –