gpt4 book ai didi

c++ - 帮助我将条目插入到 C++ std 映射中

转载 作者:行者123 更新时间:2023-11-27 22:29:21 26 4
gpt4 key购买 nike

map<int, BasicBlock*> basicBlocks; // in my header file
basicBlocks.insert(std::pair<int, BasicBlock*>(pc, bb));

其中 pc 是一个整数,bb 是一个 BasicBlock:(之前)

BasicBlock *bb = new BasicBlock(pc); 

那是从前面的代码。

我收到此错误:错误 C2664:“std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)”:无法将参数 1 从“BasicBlock *”转换为“const std::pair<_Ty1,_Ty2> &'

Why would it even need to convert the parameter? 



void ConstantPoolParser::createBasicBlocks(Method* method)
{
cout << "Creating basic block's in method: " << method->getName() << endl;
char* bytecode = method->getBytecode();
int bytecodeLength = method->getBytecodeLength();
int pc = 0;
basicBlocks.insert(new BasicBlock(pc));

for(pc = 0; pc < bytecodeLength; pc++)
{
int opcode = bytecode[pc] & 0xFF;
switch(opcode)
{
case IF_ICMPEQ: // 159 (0x9f) eq
case IF_ICMPNE: // 160 (0xa0) ne
case IF_ICMPLT: // 161 (0xa1) lt
case IF_ICMPGE: // 162 (0xa2) ge
case IF_ICMPGT: // 163 (0xa3) gt
case IF_ICMPLE: // 164 (0xa4) le
case GOTO: // 167 (0xa7) goto
{
int branchbyte1 = bytecode[pc+1] & 0xFF;
int branchbyte2 = bytecode[pc+2] & 0xFF;
int branchTarget = branchbyte1 << 8 | branchbyte2 + pc; //(branchbyte1 << 8) | branchbyte2
cout << "we got into a branch case! " << opcode << " Branch target: " << branchTarget << endl;

basicBlocks.insert( std::pair<int, BasicBlock*>(pc, new BasicBlock(pc)) );
basicBlocks.insert( std::pair<int, BasicBlock*>(branchTarget, new BasicBlock(branchTarget)) );

pc+=2; // loop will add 1 to pc
break;
}
}//end switch
}// end for
}

最佳答案

你有这条线:

basicBlocks.insert(new BasicBlock(pc));

这是试图将 BasicBlock* 插入到 map 中,而不是一对。你的意思是:

basicBlocks.insert(std::make_pair(pc, new BasicBlock(pc)) );

关于c++ - 帮助我将条目插入到 C++ std 映射中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4777854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com