如何减少定义指针功能的功能数量
我在代码中实现了一些指针函数/回调,如下所示:
typedef WndDyn* (Edit_t)(Point2d* pThis, const EditParams& EditParams);
Edit_t g_Edit_CB{ nullptr };
typedef WndDyn* (*Show_t)(const Point2d* pThis, const EditParams& EditParams);
Show_t g_Show_CB{ nullptr };
// Punkt3d
typedef WndDyn* (*Edit3d_t)(Point3d* pThis, const EditParams& EditParams);
Edit3d_t g_Edit3d_CB{ nullptr };
typedef WndDyn* (*Show3d_t)(const Point3d* pThis, const EditParams& EditParams);
Show3d_t g_Show3d_CB{ nullptr };
.
.
// Vector2d
.
.
片刻后,我意识到我正在重复指针函数,而我只是更改我的元素,即point_2d/point_3d/.... 有人可以帮助我减少功能。我正在考虑实现虚拟纯函数,但是我通常使用功能而不是指针函数来实现它们,因此我不知道该怎么做。如果有人能帮助我,我会很感激。 先感谢您
i'm implementing some pointer functions/Callbacks in my code as follow:
typedef WndDyn* (Edit_t)(Point2d* pThis, const EditParams& EditParams);
Edit_t g_Edit_CB{ nullptr };
typedef WndDyn* (*Show_t)(const Point2d* pThis, const EditParams& EditParams);
Show_t g_Show_CB{ nullptr };
// Punkt3d
typedef WndDyn* (*Edit3d_t)(Point3d* pThis, const EditParams& EditParams);
Edit3d_t g_Edit3d_CB{ nullptr };
typedef WndDyn* (*Show3d_t)(const Point3d* pThis, const EditParams& EditParams);
Show3d_t g_Show3d_CB{ nullptr };
.
.
// Vector2d
.
.
After a few moments I realized that I am repeating the pointer function and I am only changing my element which is Point_2d/Point_3d/....
Could someone help me to reduce the functions. I'm thinking about implementing virtual pure functions, but I usually implement them with functions and not pointer functions, so I have no idea how to do it. I would be very grateful if someone could help me.
Thank you in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于C ++ 11(我认为您使用
nullptr
),因此您可以使用别名模板:Since C++11 (which I assume you have available as you're using
nullptr
), you can use an alias template: