user2301299
user2301299

Reputation: 539

error: ‘template’ (as a disambiguator) is only allowed within templates

I have following definitions:

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; (*)

The problem is that when I try to compile it with gcc 4.5.3 I get following error: error: ‘template’ (as a disambiguator) is only allowed within templates In line marked with (*). In Visual Studio 2008 it compiles.

What is the reason of that? How to fix it?

Upvotes: 0

Views: 576

Answers (1)

Yakk - Adam Nevraumont
Yakk - Adam Nevraumont

Reputation: 275310

On this line:

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

remove the word template, unless you are within a template, as using ModelContainer::template ... is only valid if ModelContainer is a type dependent on non-fixed template parameters in the current scope.

If the compiler could figure out the full type of ModelContainer on that line, the use of template is not allowed. If it couldn't figure it out for certain, then the use of template is required.

Visual studio's decision to compile or not compile a given chunk of code is rarely good evidence that the code is valid C++ by any standard.

Upvotes: 2

Related Questions