是否可以使用自定义 c++ QtScript 中具有重载运算符的类?

发布于 2024-09-07 22:39:12 字数 115 浏览 1 评论 0原文

有谁知道是否可以有一个带有重载运算符(如 +、-、*)的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鯉魚旗 2024-09-14 22:39:12

这似乎是不可能的。至少这是我在#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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文