对于嵌套 typedef 使用以下语法:
typedef typename conn_table_t::template nth_index<0>::type conn_table_by_id_type;
The typename
此处使用关键字作为限定符,让编译器知道conn_table_t::template nth_index<0>::type
是一种类型。这种特殊的用途typename
仅在模板内需要。
The template
此处使用关键字作为限定符来区分成员模板和其他名称。
此外,这一行是无效的:
typedef boost::shared_ptr conn_ptr_t;
您无法键入定义模板。您只能输入 typedef 类型。也许你想写:
typedef typename boost::shared_ptr<T> conn_ptr_t;
最后一个错误:您试图给两个 typedef 赋予相同的名称:conn_table_by_id_type
你应该使用BOOST_MULTI_INDEX_CONST_MEM_FUN(T, std::string, id)
代替BOOST_MULTI_INDEX_CONST_MEM_FUN(T, std::string, T::id)
,如记录的here http://www.boost.org/doc/libs/release/libs/multi_index/doc/reference/key_extraction.html#boost_multi_index_const_mem_fun.
回应您的最后评论:此片段为我编译:
void foo(std::string id)
{
conn_table_by_id_type& id_type_view = conn_table_.template get<0>();
typename conn_table_by_id_type::const_iterator it = id_type_view.find(id);
}
Where foo
是内部的成员函数conn_mgr
模板。我猜以上就是您想要做的事情。
您应该编写辅助方法来获取对三个不同的引用conn_table_
指数。这将使事情变得更加简洁。例如:
conn_table_by_id_type & by_id_type() {return conn_table_.template get<0>();}
void foo2(std::string id)
{
typename conn_table_by_id_type::const_iterator it = by_id_type().find(id);
}