当有一个类:
class Point{
public:
Point(int x_=0){m_x=x_;}int getX(){return m_x;}void setX(int x_){m_x=x_;}
private:int m_x;
};
以及注册内容:
EMSCRIPTEN_BINDINGS(my_value_example) {emscripten::class_<Point>("Point").constructor<int>().property("m_x", &Point::getX, &Point::setX);
}
将Point的m_x作为属性注册时,运行会报错:
instantiation of undefined template 'emscripten::internal::GetterPolicy<int (Point::*)()>'auto gter = &GP::template get<ClassType>;
in instantiation of function template specialization'emscripten::class_<Point>::property<emscripten::internal::DeduceArgumentsTag, int (Point::*)(), void(Point::*)(int)>' requested here.property("m_x", &Point::getX, &Point::setX);
原因是get方法必须是const的,也就是需要换成如下写法:
int getX() const {return m_x;}