5

クラスから静的フィールドをエクスポートしようとしています:

class Foo
{
   const static int Var;
};

// luabind module:
.def_readonly("Var", &Foo::Var);
// I've also tried
.def_readonly("Var", Foo::Var);
 error: no matching function for call to ‘luabind::class_<Foo>::def_readonly(const char [6], const Foo&)’
 note: template<class C, class D> luabind::class_& luabind::class_::def_readwrite(const char*, D C::*)

私は何を逃したのですか?

4

1 に答える 1

3

ドキュメントで明確に述べられているように、静的関数 (とりわけ) はメンバーとして追加できません。それらは、特別な構造でスコープする必要があります.scope

class_<foo>("foo")
    .def(constructor<>())
    .scope
    [
        class_<inner>("nested"),
        def("f", &f)
    ];

defの非メンバー関数バージョンにreadonly変数のバージョンがあるかどうかはわかりませんが、あるかもしれません。そうでない場合は、値を返す関数として公開する必要があります。

于 2012-02-26T08:43:08.460 に答える