0

我有一堆子类,每个子类都有不同参数数量和类型的静态类工厂方法,并且还想从使用jsonpp的 json 数据文件加载的数据中实例化它们。

所以说我将有一个 Json::Value 对象数组作为参数,有没有一种聪明的方法,使用宏或 C++ 中的东西来创建接受 Json::Value 数组并调用原始方法的替代代理方法,例如)

Foo* Foo::create(int a, const char* b) { /* ... */ }
Foo* Foo::create(Json::Value args) { //the Json::Value args represents an array value here
    // can I avoid having to manually create each of these Json methods?
    return Foo::create(args[0].asInt(), args[1].asCString());
}

抱歉,我的 c++ 仍在跟上速度。我发现了一些似乎处理解包元组参数的主题,例如,

但我不确定要采用哪种方法。谢谢您的帮助

4

0 回答 0