2013-01-30 23 views
5

Tôi muốn một thùng chứa nhiều chỉ mục trong một lớp, điều đó phụ thuộc vào một lớp phụ thuộc vào mẫu trong lớp. Âm thanh phức tạp, đây là mã:tăng nhiều thùng chứa chỉ mục của cấu trúc phụ thuộc vào mẫu trong lớp mẫu

#include <boost/unordered_map.hpp> 
#include <boost/multi_index_container.hpp> 
#include <boost/multi_index/hashed_index.hpp> 
#include <boost/multi_index/random_access_index.hpp> 
#include <boost/multi_index/ordered_index.hpp> 
#include <boost/multi_index/member.hpp> 

template <typename Type> 
class myDataContainer{ 
public: 
    struct DataStruct{ 
     double t; 
     std::vector<Type> data; 
    }; 

    // indices structs 
    struct TagTime{}; 
    struct TagOrdered{}; 

    typedef boost::multi_index::multi_index_container< 
    DataStruct, 
    boost::multi_index::indexed_by< 
     boost::multi_index::hashed_unique<boost::multi_index::tag<TagTime>,  boost::multi_index::member<DataStruct, double, &DataStruct::t> >, 
     boost::multi_index::ordered_unique<boost::multi_index::tag<TagOrdered>,  boost::multi_index::member<DataStruct, double, &DataStruct::t> > // this index represents  timestamp incremental order 
     > 
    > InnerDataContainer; 
    typedef typename boost::multi_index::index<InnerDataContainer,TagTime>::type timestamp_view; 
    typedef typename boost::multi_index::index<InnerDataContainer,TagOrdered>::type ordered_view; 

    InnerDataContainer dataContainer; 
    void begin(){ 
     ordered_view& ordView = dataContainer.get<TagOrdered>(); 
     ordView.begin(); 
    } 

}; 

int main(int argc, char *argv[]) 
{ 
    myDataContainer<float> data; 
    myDataContainer<float>::ordered_view& ordView = data.dataContainer.get<TagOrder>(); 
    ordView.begin(); 
} 

Nếu không có chức năng myDataContainer::begin() mã này biên dịch, nhưng với sự myDataContainer::begin() tôi nhận được lỗi sau:

main.cpp: In member function 'void myDataContainer<Type>::begin()': 
main.cpp:134:66: error: expected primary-expression before '>' token 
main.cpp:134:68: error: expected primary-expression before ')' token 

Am tôi thiếu cái gì? Đây có phải là một lỗi trong thúc đẩy hoặc là nó không thể? '

Cảm ơn trước veio

Trả lời

5

Vì dataContainer là mẫu tham số phụ thuộc, bạn cần

ordered_view& ordView = dataContainer.template get<TagOrdered>(); 

Trong main() bạn sử dụng cụ thể một chuyên môn hóa, vì vậy không có biểu thức phụ thuộc nữa.

+0

uh, bạn đá, hoạt động. Cảm ơn bạn! – veio

Các vấn đề liên quan