【问题标题】:Error with "addProperty" in LuabridgeLuabridge 中的“addProperty”错误
【发布时间】:2015-10-15 02:14:05
【问题描述】:

我有一些非常简单的源代码来公开一个简单的Foo 类。

main.cpp:

#include <iostream>

#include <lua.hpp>
#include <LuaBridge.h>

class Foo
{
    private:
        int number = 0;

    public:
        void setNumber(const int& newNumber) {number = newNumber;}
        int getNumber() {return number;}
};

int main()
{
    //Expose the API:
    lua_State* L = luaL_newstate();
    luaL_openlibs(L);
    luabridge::getGlobalNamespace(L)
    .beginClass<Foo>("Foo")
        .addConstructor<void(*)(void)>()
        .addProperty("number", &Foo::getNumber, &Foo::setNumber)
    .endClass();
}

不幸的是,我收到了这个错误:

24 error: no matching function for call to ‘luabridge::Namespace::Class<Foo>::addProperty(const char [7], int (Foo::*)(), void (Foo::*)(const int&))’

我不知道问题是什么,但我必须使用addProperty 否则代码看起来不正确

【问题讨论】:

    标签: c++ lua luabridge


    【解决方案1】:

    addProperty的模板:

    template <class TG, class TS>
    Class <T>& addProperty (char const* name, TG (T::* get) () const, void (T::* set) (TS))
    

    要求 getter 是 const 成员函数。 将吸气剂更改为:

    int getNumber() const { return number; }
    

    消除 LuaBridge 2.0 中的错误

    【讨论】:

    • 将 getter 设置为 const 并不能解决问题,甚至不会更改错误消息
    • 它使用 Lua 5.2 和 LuaBridge 2.0 为我创建和消除错误
    • @Orfby 你有哪个版本的 LuaBridge?
    • 最新版本(来自 GitHub)。我会尝试重新安装
    • 刚刚重新安装(LuaBridge 2.0),必须进行一些更改,否则无法编译(来自here),仍然无法修复它。你有什么版本的 LuaBridge,得到一个干净的副本后是否出现错误?
    猜你喜欢
    • 2014-09-27
    • 2020-12-15
    • 2014-06-21
    • 2013-12-12
    • 1970-01-01
    • 2012-11-01
    • 1970-01-01
    • 2021-09-29
    • 2015-11-20
    相关资源
    最近更新 更多