1

我正在使用第三方库开发一个项目,这些库使用一些在 .cpp 文件中声明和定义类的脚本。他们使用外部构造函数初始化这些类,该构造函数在迭代器中注册要在触发事件上执行的实例。

通过这种方式,这些类似乎无法从外部文件访问。但是我需要使用一种非侵入性的方法来使用它们以某种不需要重写第三方代码的方式

这是伪场景:

“脚本.cpp”

#include "ScriptLoader.h"
class theirScript {
    public:
        theirScript() : RegisterScript("theirScript") {}

        static void anUsefullStaticMethod() { ... }
}

void addTheirScript() {
    new theirScript();
}

“脚本加载器.h”

void addTheirScript();

“脚本加载器.cpp”

#include "ScriptLoader.h"
addTheirScript();

“我的文件.cpp”

#include "ScriptLoader.h"
theirScript::anUsefullStaticMethod(); // will never work

那我怎样才能访问“theirScript”类呢?有没有办法让我不必重写他们的代码?

4

0 回答 0