2

AngelScriptの周りに薄いラッパーを書き込もうとしています。特定の構造体をラップする方法がわかりません。

ラップしたい構造体の構造体定義は次のasSMethodPtrとおりです。

template <int N>
struct asSMethodPtr
{
    template<class M>
    static asSFuncPtr Convert(M Mthd)
    {
        // This version of the function should never be executed, nor compiled,
        // as it would mean that the size of the method pointer cannot be determined.

        int ERROR_UnsupportedMethodPtr[N-100];

        asSFuncPtr p;
        return p;
    }
};

の定義は次のasSFuncPtrとおりです。

struct asSFuncPtr
{
    union
    {
        char dummy[25]; // largest known class method pointer
        struct {asFUNCTION_t func; char dummy[25-sizeof(asFUNCTION_t)];} f;
    } ptr;
    asBYTE flag; // 1 = generic, 2 = global func
};

これが私が見つけた(AngelBinderライブラリから取得した)コードで、それを「ラップ」することができます:

template<typename R> ClassExporter& method(std::string name, R (T::*func)())
{
    MethodClass mthd(name, Type<R>::toString(), asSMethodPtr< sizeof( void (T::*)() ) >::Convert( AS_METHOD_AMBIGUITY_CAST( R (T::*)()) (func) ));
    this->_methods.push(mthd);
    return *this;
}

残念ながら、このコードが何をしているのかわかりません...

T::*をすべきですか?クラス型へのポインタ?

とはR (T::*func)()?

助けていただければ幸いです...

4

1 に答える 1

2

T::*メンバーへのポインターです。 0 のパラメーターR (T::*func)()を返し、受け取るメンバー関数へのポインターです。R例えば:

struct S
{
    int f()
    {
        return 5;
    }

    int x = 10;
};

int main()
{
    S s;

    int S::* ptr = &S::x;

    std::cout << s.*ptr; // 10

    int (S::*f_ptr)() = &S::f;

    std::cout << (s.*f_ptr)(); // 5
}

詳細はこちらをご覧ください

于 2013-04-27T01:29:18.020 に答える