0

我有以下定义:

typedef  boost::multi_index_container<
  ModelPtr,
   boost::multi_index::indexed_by<
    boost::multi_index::sequenced<boost::multi_index::tag<byInsertOrder> >, // to keep order of inserting
    boost::multi_index::ordered_non_unique< boost::multi_index::tag<byPriority>,
                                            boost::multi_index::const_mem_fun<IModel,
                                            unsigned int,
                                            &IModel::getPriority>,
                                            std::greater< unsigned int> // from the highest priority to the lowest
                                            >
    >
  > ModelContainer;

typedef ModelContainer::template index<AOActivationList::byInsertOrder>::type ModelByInsertOrderType; (*)

问题是,当我尝试使用 gcc 4.5.3 编译它时,出现以下错误:错误:“模板”(作为消歧符)仅允许在标有 (*) 的模板中使用。在 Visual Studio 2008 中,它可以编译。

这是什么原因?如何解决?

4

1 回答 1

2

在这条线上:

typedef ModelContainer::template index<AOActivationList::byInsertOrder>::type ModelByInsertOrderType

删除 word template,除非您在 a 内template,因为 using仅在依赖于当前范围内的非固定参数的类型ModelContainer::template ...时才有效。ModelContainertemplate

如果编译器可以找出该行的完整类型,则不允许ModelContainer使用 of 。template如果无法确定,则template需要使用 。

Visual Studio 编译或不编译给定代码块的决定很少能很好地证明该代码在任何标准下都是有效的 C++。

于 2013-06-12T00:22:10.493 回答