gpt4 book ai didi

c++ - 错误 : ‘template’ (as a disambiguator) is only allowed within templates

转载 作者:行者123 更新时间:2023-11-28 03:15:23 25 4
gpt4 key购买 nike

我有以下定义:

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 编译它时出现以下错误:错误:"template"(作为消歧器)只允许在模板中使用在标有 (*) 的行中。在 Visual Studio 2008 中编译。

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

最佳答案

在这一行:

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

删除单词 template,除非你在 template 中,因为使用 ModelContainer::template ... 只有在 ModelContainer 是一种依赖于当前范围内非固定 template 参数的类型。

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

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

关于c++ - 错误 : ‘template’ (as a disambiguator) is only allowed within templates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17055836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com