【发布时间】:2011-07-12 10:45:34
【问题描述】:
我需要创建一个包含多索引容器作为存储的通用类。当我编译时,它给出了如下错误,我定义了第 n 个索引视图。
错误:非模板“nth_index”用作模板
/**
* connection manager
*/
template < typename T, typename C >
class conn_mgr: boost::noncopyable {
public:
/**
* connection ptr
*/
typedef boost::shared_ptr conn_ptr_t;
/**
* connection table type
* It's a multi index container
*/
typedef boost::multi_index::multi_index_container <
conn_ptr_t,
boost::multi_index::indexed_by <
//sequenced < >,
boost::multi_index::hashed_unique <
BOOST_MULTI_INDEX_CONST_MEM_FUN(T, std::string, T::id) >,
boost::multi_index::hashed_non_unique <
BOOST_MULTI_INDEX_CONST_MEM_FUN(T, std::string,
T::type)>,
boost::multi_index::hashed_non_unique <
boost::multi_index::composite_key < conn_ptr_t,
BOOST_MULTI_INDEX_CONST_MEM_FUN(T,
std::string, T::id),
BOOST_MULTI_INDEX_CONST_MEM_FUN(T,
std::string, T::type ) > > > >
conn_table_t;
//typedef for ConnectionIdView
typedef conn_table_t::nth_index<0>::type conn_table_by_id_type;
typedef conn_table_t::nth_index<1>::type conn_table_by_type;
typedef conn_table_t::nth_index<2>::type conn_table_by_id_type;
私人: conn_table_t conn_table_; };
这里是我在 main 中的使用方式。
int main(int argc, char** argv) { typedef conn_mgr smpp_conn_mgr_t; smpp_conn_mgr_t conn_mgr; }
【问题讨论】:
-
您不能 typedef 模板。此行无效:
typedef boost::shared_ptr conn_ptr_t;
标签: c++ templates boost boost-multi-index