如何通过 GUI 使用通用编程?

发布于 2024-12-29 10:07:44 字数 268 浏览 0 评论 0原文

我使用通用编程技术开发了一个大型程序,其中涉及大量类模板。有没有办法根据 GUI 选项在运行时模拟选择这些参数?

假设我有 a

template <typename A, typename B, typename C>
class MyClass {};

,我想从 3 组单选按钮中选择 A、B 和 C。在不进行组合长 switch 语句的情况下,是否有任何方法可以使用用户在 GUI 中选择的类型来实例化 MyClass?

I have developed a big program using techniques of generic programming, which involve lots of class templates. Is there anyway to simulate choosing these parameters at runtime based on GUI options?

Say I have a

template <typename A, typename B, typename C>
class MyClass {};

and I want to choose A, B, and C from 3 groups of radio buttons. Without making a combinatorially long switch statement, is there any way to instantiate MyClass using the types that the user selects in the GUI?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

苍白女子 2025-01-05 10:07:44

我不是这里的专家,但我确实相信,正如其他人在评论中提到的那样,这是不可能的。

您也许可以编写一个 GUI 应用程序来更改模板文件中的参数,并开始该项目的编译和执行。我们经常做类似的事情,以便使用不同的编译目标/环境对我们的代码进行单元测试,这听起来基本上就是您想要做的事情。

I am not an expert here, but I do believe that as others mentioned in comments that this isn't possible.

What you could perhaps do is write a GUI application that changed parameters in a template file, and kicked off the compilation and execution of this project. We often do similar things in order to unit test our code with different compilation targets/environments, and that sounds like essentially what you are trying to do.

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