5

我想要一个类中的多索引容器,这取决于类中依赖于模板的类。听起来很复杂,代码如下:

#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();
}

如果没有myDataContainer::begin()此代码编译的函数,但出现myDataContainer::begin()以下错误:

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

我错过了什么吗?这是提升中的错误还是不可能?

在此先感谢

4

1 回答 1

5

因为 dataContainer 依赖于模板参数,所以你需要

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

main()您使用特定的专业化时,因此不再有依赖表达式。

于 2013-01-30T23:00:57.120 回答