C ++中的通用属性访问

问题描述

我多次使用此包装器功能。有没有办法从中编写通用模板?

void setFoo(const Napi::CallbackInfo &info)
{
    if (info.Length() < 1 || !info[0].IsNumber()) {
        Napi::TypeError::New(info.Env(),"arg1::Number expected").ThrowAsJavaScriptException();
    }

    object->foo= info[0].As<Napi::Number>().DoubleValue();
}

例如,我希望拥有:

setFoo (that sets the value of object->foo)
setBar (that sets the value of object->bar)
setFoobar (that sets the value of object->foobar)
setWhatever...

这在C ++中可行吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)