emscripten 中的错误绑定属性和函数

Error binding properties and functions in emscripten

我正在尝试使用 emscripten 编译 C++ class 并公开绑定。我 运行 遇到编译器错误。

#include <emscripten/bind.h>
#include <emscripten/emscripten.h>


using namespace emscripten;

class  MyClass {
private:
    int _year;
    int _month;
    int _day;
public:
    MyClass() { }
    MyClass(int year, int month, int day);

    int getMonth();
    void setMonth(int);
    int getYear();
    void setYear(int);
    int getDay();
    void setDay(int);
    bool isLeapYear();
    int daysInMonth();

    void increment();
    void decrement();
};

EMSCRIPTEN_BINDINGS(my_sample_class) {
class_<MyClass>("MyClass") 
    .constructor<>()
    .constructor<int, int, int>()
    .function("getMonth",  &MyClass::getMonth)
    .function("increment", &MyClass::increment)
    .function("decrement", &MyClass::decrement)
    .property("year",&MyClass::getYear, &MyClass::setYear )
    //.property("month", &MyClass::getMonth, &MyClass::setMonth )
    //.property("day",&MyClass::getDay, &MyClass::setDay )
    ;
}

编译器在构造函数或函数绑定方面没有问题。我 运行 遇到了 属性 绑定的问题。我只有一个未注释的,以尽量减少我返回的错误(它们只是相同错误的重复,但针对不同的行)。这是我回来的错误。

In file included from MyDate.cpp:1:
In file included from ./MyDate.h:2:

emscripten/bind.h:1393:26: error: implicit instantiation of undefined template 'emscripten::internal::GetterPolicy<int (MyClass::*)()>'

        auto gter = &GP::template get<ClassType>;
                     ^
./MyDate.h:37:6: note: in instantiation of function template specialization 'emscripten::class_<MyClass, emscripten::internal::NoBaseClass>::property<int (MyClass::*)(), void (MyClass::*)(int)>' requested here
.property("year",&MyClass::getYear, &MyClass::setYear )
 ^ 



 emscripten/bind.h:569:16: note: template is declared here

    struct GetterPolicy;
           ^
emscripten/bind.h:1399:33: error: implicit instantiation of undefined template 'emscripten::internal::GetterPolicy<int (MyClass::*)()>'
            TypeID<typename GP::ReturnType>::get(),
                            ^
emscripten.38.21\system\include\emscripten/bind.h:569:16: note: template is declared here
    struct GetterPolicy;
           ^
2 errors generated.
shared:ERROR: compiler frontend failed to generate LLVM bitcode, halting

我查阅了绑定示例,看来我使用的是正确的语法。有人知道我可能做错了什么吗?

找到问题了!

getter 函数必须标记为 const 以避免这些错误。 前任: int getMonth() const;