2012-01-25 13 views
1

新しいイベントクラスの定義を簡単にするために使用するクラステンプレートはDefineEventです。私が言って、DefineEvent()::SetOnce<Parents...>ラインを指してコンパイル・エラーが発生します関数呼び出しでテンプレート引数を展開する方法は?

template<class EventClass> 
class TypeInfoParentSetter 
{ 
    public: 
    template<class... Parents> 
    static const EventTypeInfo& SetOnce(TypeInfoHolder<EventClass>& holder) 
    { 
     // ... 
    } 
}; 

:私が使用TypeInfoParentSetterクラスは次のようにそこに見える

template<class EventClass, class... Parents> 
class DefineEvent : public virtual Event, public Parents... 
{ 
    public: 
    DefineEvent() 
    { 
     static const EventTypeInfo& info = TypeInfoParentSetter<EventClass> 
      ::SetOnce<Parents...>(TypeInfoHolder<EventClass>::Instance()); 
    } 
}; 

:この(かなり毛深い、私が知っている)のように見えています私はコンパイラが "...の前にプライマリ表現を期待していた"トークン "。これをどうやって解決するのですか?

hereという文脈でコードを表示できますが、かなり醜いことに注意してください。

答えて

4

はテンプレートです:

DefineEvent() 
    { 
     static const EventTypeInfo& info = TypeInfoParentSetter<EventClass> 
      :: template SetOnce<Parents...>(TypeInfoHolder<EventClass>::Instance()); 
    } 

、あなたはメンバーを作るのを忘れて静的関数TypeInfoParentSetter<EventClass>::Set

template<class... Parents> 
    static TypeInfoParentSetter<EventClass> Set(TypeInfoHolder<EventClass>& holder) 
    { 
     std::cout << "ParentSetter()\n"; 
     return TypeInfoParentSetter<EventClass>(); 
    } 

チェックそれ:http://ideone.com/sNHMX

0

はあなたがSetOnce前に「テンプレート」キーワードを使用しなければならないかもしれませ:あなたは、ネストされた名前を示すために1つのテンプレートのキーワードを含める必要が

template<class EventClass, class... Parents> 
class DefineEvent : public virtual EventClass, public Parents... 
{ 
    public: 
    DefineEvent() 
    { 
     static const EventTypeInfo& info = 
      TypeInfoParentSetter<EventClass>::template SetOnce<Parents ...>(TypeInfoHolder<EventClass>::Instance()); 
    } 
}; 
関連する問題