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 でコンパイルしようとすると、次のエラーが発生することです: エラー: 'template' (曖昧さ回避ツールとして) は、(*) でマークされたテンプレート内の行でのみ許可されます。Visual Studio 2008 ではコンパイルされます。

その理由は何ですか?修正方法は?

4

1 に答える 1

2

この行で:

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

が現在のスコープ内の固定されていないパラメーターに依存する型である場合にのみ使用できるため、template内にいる場合を除き、 という単語を削除します。templateModelContainer::template ...ModelContainertemplate

コンパイラがその行の の完全な型を把握できた場合、ModelContainerの使用はtemplate許可されません。確実に把握できなかった場合は、 を使用するtemplate必要があります。

コードの特定のチャンクをコンパイルするかコンパイルしないかという Visual Studio の決定は、そのコードが標準で有効な C++ であるという良い証拠になることはめったにありません。

于 2013-06-12T00:22:10.493 に答える