gpt4 book ai didi

c++ - emscripten 中的错误绑定(bind)属性和函数

转载 作者:行者123 更新时间:2023-12-01 14:44:26 34 4
gpt4 key购买 nike

我正在尝试使用 emscripten 编译 C++ 类并公开绑定(bind)。我遇到了编译器错误。

#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 )
;
}

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

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\1.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

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

最佳答案

找到问题了!

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

关于c++ - emscripten 中的错误绑定(bind)属性和函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54015006/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com