虚函数数组

发布于 2024-11-29 13:08:48 字数 962 浏览 0 评论 0原文

当逆向工程和使用外部类时,我经常尝试重新定义库中的这些类:

class GameEngine // Exported with "GetGameEngine"
{
public:
    virtual void foo1() = 0;
    virtual void foo2() = 0;
    virtual void foo3() = 0;
    virtual void foo4() = 0;
    virtual void foo5() = 0;
    virtual void foo6() = 0;
    virtual void foo7() = 0;
    virtual void foo8() = 0;
    virtual void foo9() = 0;
    virtual void foo10() = 0;
    virtual void foo11() = 0;
    virtual void foo12() = 0;
    virtual int GetGameStatus() = 0; //0x30
    virtual void foo14() = 0;
    virtual void foo15() = 0;
    virtual void foo16() = 0;
    virtual int AnotherUsefulFunction() = 0; //0x40
};

基本上我在外部调用 GetGameStatus 函数。是否有某种结构或可能性允许我这样写:

class GameEngine // Exported with "GetGameEngine"
{
public:
    FUNCTABLE(12);
    virtual int GetGameStatus() = 0; //0x30
    FUNCTABLE(14,16);
    virtual int AnotherUsefulFunction() = 0; //0x40
};

它会清理我的代码很多。

When reverse engineering and using external classes I often try to redefine those classes in my library:

class GameEngine // Exported with "GetGameEngine"
{
public:
    virtual void foo1() = 0;
    virtual void foo2() = 0;
    virtual void foo3() = 0;
    virtual void foo4() = 0;
    virtual void foo5() = 0;
    virtual void foo6() = 0;
    virtual void foo7() = 0;
    virtual void foo8() = 0;
    virtual void foo9() = 0;
    virtual void foo10() = 0;
    virtual void foo11() = 0;
    virtual void foo12() = 0;
    virtual int GetGameStatus() = 0; //0x30
    virtual void foo14() = 0;
    virtual void foo15() = 0;
    virtual void foo16() = 0;
    virtual int AnotherUsefulFunction() = 0; //0x40
};

Basically I call the GetGameStatus function externally. Is there some structure or a possibility that allows me to write it this like:

class GameEngine // Exported with "GetGameEngine"
{
public:
    FUNCTABLE(12);
    virtual int GetGameStatus() = 0; //0x30
    FUNCTABLE(14,16);
    virtual int AnotherUsefulFunction() = 0; //0x40
};

It would clean up my code a lot.

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

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

发布评论

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

评论(1

一瞬间的火花 2024-12-06 13:08:48

查看 boost::preprocessor,具体位于它的 REPEAT 宏。像这样的东西应该有效:

#include <boost/preprocessor/repetition/repeat.hpp>

#define FUNC(fun_z, fun_n, fun_data) virtual void foo ## fun_n () = 0;
#define FUNCTABLE(count) BOOST_PP_REPEAT(count, FUNC, 0)

Look at boost::preprocessor, specifically at its REPEAT macro. Something like this should work:

#include <boost/preprocessor/repetition/repeat.hpp>

#define FUNC(fun_z, fun_n, fun_data) virtual void foo ## fun_n () = 0;
#define FUNCTABLE(count) BOOST_PP_REPEAT(count, FUNC, 0)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文