0

IO<T>テンプレートクラスと別のテンプレートクラスがあるとしましょうMembershipFunction<T>。私の物にはMembershipFunction<T>*sのベクトルが必要であり、 fromからまでも必要です。私にとって、このような複雑なコードで物事を思い出すことは不可能です。特にイテレータを使用する場合。だから私はにいくつかのsを追加しようとしました。しかし、コンパイラはネストされたテンプレートを見ることができないようです。エラーは以下のとおりです。IOstd::mapstd::stringMembershipFunction<T>*typedefIO

克服するにはどうすればよいですか?

#include <vector>
#include <map>
#include <string>
#include <utility>
#include "membership_function.h" // for the love of god! 
                                 // MembershipFunction is defined there!
#include "FFIS_global.h"


template <typename T>
class DLL_SHARED_EXPORT IO
{
private:
    typedef std::pair<std::string,  MembershipFunction<T>* > MapEntry; // (1)
    typedef std::map<std::string, MembershipFunction<T>* > Map; // (2)
    typedef std::vector<const MembershipFunction<T>* > Vector; // (3)
    // And so on...

これらはエラーです:

(1) error: 'MembershipFunction' was not declared in this scope
(1) error: template argument 2 is invalid
(1) error: expected unqualified-id before '>' token
(2 and 3): same errors 

編集:

これはのコードですMembershipFunction

template <typename T>
class DLL_SHARED_EXPORT MembershipFunction
{
public:
    virtual T value(const T& input) const{return T();}
    virtual void setImplicationMethod(const typename  MFIS<T>::Implication& method);
};
4

2 に答える 2

2

コードをコピーして貼り付けたところ、gcc で正常にコンパイルされました。テンプレートの使用に問題はありません。コンパイラ エラーは、以前に型を見たことがないことを示しています。ファイルをインクルードするかどうかは気にしません。何らかの理由で、コンパイラは完全な定義を認識しません。前方宣言では不十分な場合があります。また、その DLL_SHARED_EXPORT が何であるかは不明です。それが原因であると思われます。

私に反対票を投じる前に、これをコンパイルして自分の目で確かめてください。

#include <vector>
#include <map>
#include <utility>

template <typename T>
class  MembershipFunction
{
public:
    virtual T value(const T& input) const{return T();}
    //virtual void setImplicationMethod(const typename  MFIS<T>::Implication& method);
};


template <typename T>
class IO
{
private:
    typedef std::pair<std::string,  MembershipFunction<T>* > MapEntry; // (1)
    typedef std::map<std::string, MembershipFunction<T>* > Map; // (2)
    typedef std::vector<const MembershipFunction<T>* > Vector; // (3)
};
于 2012-07-13T20:12:51.740 に答える
-1

MembershipFunctionで使用する前に定義する必要がありIOます。最初に来ることを確認してください。それらが別々のファイルにある場合#includeは、一方が他方にあります。

于 2012-07-13T19:56:00.767 に答える