开发者

Array of virtual functions

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
    virt开发者_如何学Goual 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.


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜