所以我将程序从Python移植到c ++,我在这里有这段代码:
opcodes = [
[0x1,'0x1',['b','b',]],
[0x2,'call',['d',]],
[0x3,'0x3',['w',]],
[0x4,'0x4-return',[]],
[0x5,'0x5',[]],
[0x6,'0x6-condjump',['d']],
[0x7,'0x7-condjump',['d']],
[0x8,'0x8',[]],
[0x9,'0x9',[]],
[0xa,'0xa',['d',]],
[0xb,'0xb',['w',]],
[0xc,'0xc',['b',]],
[0xe,'string',['str']],
[0xf,'0xf',['w',]],
[0x10,'0x10',['b',]],
[0x11,'0x11',['w',]],
[0x12,'0x12',['b',]],
[0x14,'0x14',[]],
[0x15,'0x15',['w',]],
[0x16,'0x16',['b',]],
[0x17,'0x17',['w',]],
[0x18,'0x18',['b']],
[0x19,'0x19',[]],
[0x1a,'0x1a',[]],
]
我想知道将此转换为C ++数组的最佳方法是什么。我对python不太熟悉抱歉,听说这叫做嵌套列表?
提前感谢所有答案,这可能是python代码的最大障碍。
答案 0 :(得分:2)
创建一个包含[0x1,'0x1',['b','b',]]
的结构或类,类似于
struct shmizzle {
int forpult;
char *yorgole;
char **flubbo;
};
课程可能更容易,因为您可以更轻松地初始化它。我不是C ++专家。
答案 1 :(得分:2)
这是C ++ 11:
#include <string>
#include <vector>
struct OpCode {
int code;
const char* str;
std::vector<const char*> extras;
};
OpCode opcodes[] = {
{0x1,"0x1",{"b","b",}},
{0x2,"call",{"d",}},
{0x3,"0x3",{"w",}},
{0x4,"0x4-return",{}},
{0x5,"0x5",{}},
{0x6,"0x6-condjump",{"d"}},
{0x7,"0x7-condjump",{"d"}},
{0x8,"0x8",{}},
{0x9,"0x9",{}},
{0xa,"0xa",{"d",}},
{0xb,"0xb",{"w",}},
{0xc,"0xc",{"b",}},
{0xe,"string",{"str"}},
{0xf,"0xf",{"w",}},
{0x10,"0x10",{"b",}},
{0x11,"0x11",{"w",}},
{0x12,"0x12",{"b",}},
{0x14,"0x14",{}},
{0x15,"0x15",{"w",}},
{0x16,"0x16",{"b",}},
{0x17,"0x17",{"w",}},
{0x18,"0x18",{"b"}},
{0x19,"0x19",{}},
{0x1a,"0x1a",{}},
};