是否可以使用自定义 c++ QtScript 中具有重载运算符的类?
有谁知道是否可以有一个带有重载运算符(如 +、-、*)的 C++ 类,并以某种方式将其声明(这就是魔法发生的地方)到 QtScriptEngine,以便评估像“a+b”这样的 js 表达式因为他们会在 C++ 方面?
Does anyone know if it is possible to have a C++ class with overloaded operators such as +,-,* and declare it somehow (this is where the magic happens) to a QtScriptEngine such that js-expressions like "a+b" are evaluated as they would be on the C++ side?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这似乎是不可能的。至少这是我在#qt-labs IRC 中收到的答案。
不过,我认为我找到了一个可行的替代方案:ChaiScript。它完美地嵌入到 C++ 中,与 Qt 配合良好,并允许重载运算符,甚至更好地直接使用任何(?)C++ 数据类型。
It seems to be impossible. At least that is what I received as an answer in the #qt-labs IRC.
However, I think I found a viable alternative: ChaiScript. It embeds itself wonderfully into C++, plays well with Qt and allows for the overloading of operators, and even better the direct use of any(?) C++ data type.