1

私のプログラムには 2 つの主要な部分が含まれています。1 つは DLL 内の C++ クラス定義で、もう 1 つはコア プログラムです。各 DLL がコア プログラムにロードされた後、Proxy クラスはクラス記述をコア プログラムのデータ構造に入力します。これはキーワード「extern」を使用して解決されます。

エラーメッセージで宣言の順序に問題がありました。コード行:「typedef map method_map;」1. エラー: 'proxy' はこのスコープで宣言されていません 2. エラー: テンプレート引数 2 がコード行で無効です:

typedef common_object *maker_t();
extern map< string, maker_t* > factory;


//This method_map is used to store all the method structure data of each class
//method: class_name, method_name, function pointer
//I got two errors here:
//1. "ERROR: ‘proxy’ was not declared in this scope"
//2. "ERROR: ‘error: template argument 2 is invalid"
typedef map<string, proxy::method> method_map;
//this class_map contain the methods description for each class.
//this class_map is declared in the core program.
//after the class in this dll is loaded on the core program,
//it would automatically fill its descriptino in here
extern  map<string, method_map> class_map_;

// our global factory
template<typename T>
class proxy {
public:
typedef int (T::*mfp)(lua_State *L);
typedef struct {
    const char *class_name;
    const char *method_name;
    mfp mfunc;
} method;

proxy() {
    std::cout << "circle proxy" << endl;
    // the loop for filling the methods information of the class T
    method_map method_map_;
    for (method *m = T::methods;m->method_name; m++) {
        method m1; //specific information about each method
        m1.class_name = T::className;
        m1.method_name = m->method_name;
        m1.mfunc = m->mfunc;
        method_map_[m1.method_name] = m1; //assign m1 into the method map
    }
    //Assign methods description of the T class into the class_map
    class_map_[T::class_name] = method_map_;
}
};    

この問題に関するアドバイスをお待ちしております。本当にありがとう!

4

2 に答える 2

1

method_mapまた、別のネストされたタイプ( )に依存し、それがテンプレートパラメータに依存するため、内部(または他のテンプレート)にclass_map_ネストする必要があります。proxymethod

そうでない場合(たとえばproxy、テンプレートではなくクラスの場合)、proxyそこで宣言された型を使用するには、後で宣言する必要があります。

于 2012-11-28T10:56:17.187 に答える
0

class proxy;前に定義/宣言するtypedef map<string, proxy::method> method_map;

そのようです:

    template<class T>
    class proxy;
    typedef map<string, proxy::method> method_map;
于 2012-11-28T10:57:22.333 に答える