2016-10-27 5 views
2

ではありません。エラー:「T」を、私はユースケースで、以下の機能を持っているテンプレート

template<size_t state_dim, size_t action_dim> 
class agent { 
    // [...] 
    /** 
    * @brief get_plugin Get a pluging by name 
    */ 
    template<typename T> 
    inline T<state_dim, action_dim>* get_plugin() const { 
     const string plugin = T<state_dim, action_dim>().name(); 
     for(size_t i = 0; i < this->_plugins.size(); i++) 
      if(this->_plugins[i].first == plugin) 
       return static_cast<T<state_dim, action_dim>*>(this->_plugins.at(i).second); 
     return nullptr; 
    } 
    // [...] 
} 

// a possible usecase 
auto sepp = instance.get_plugin<plugin_SEP>(); 

しかし、私は次のエラーを取得:

error: 'T' is not a template 
    inline T<state_dim, action_dim>* get_plugin(const string& plugin) const { 
     ^

error: 'T' is not a template 
    return static_cast<T<state_dim, action_dim>*>(this->_plugins.at(i).second); 
        ^

error: missing template arguments before '>' token 
    auto sepp = instance.get_plugin<plugin_SEP>(); 
              ^

error: expected primary-expression before ')' token 
    auto sepp = instance.get_plugin<plugin_SEP>(); 
               ^

私がここで行方不明です何を?

+1

'typename T 'では、' T'は*型*と言っています。それでも後で*テンプレート*として使用しようとしています。タイプとテンプレートは全く異なる2つのものです。なぜあなたはテンプレート名として型名を使用しようとしていますか? – AnT

答えて

2

1. Ttemplate template parameterであることを宣言する必要があります。そうしないと、テンプレート引数では使用できません(インスタンス化することはできません)。

template <template <size_t, size_t> class T> 
inline T<state_dim, action_dim>* get_plugin(const string& plugin) const { 

2.Youは、メンバ関数テンプレートget_pluginを呼び出すためのキーワードtemplateを挿入する必要があります。

auto sepp = instance.template get_plugin<plugin_SEP>(); 

詳細はWhere and why do I have to put the “template” and “typename” keywords?を参照してください。

+0

これはエラーの最初のカップルを修正しましたが、最後のカップルのエラーはまだ有効です! – dariush

+0

@dariush 'auto sepp = instance.template get_pluginを試してください();' – songyuanyao

+0

いいです、それは仕事をしましたが、一体何が意味ですか、それは何ですか?/ – dariush

関連する問題