我正在尝试用2个值初始化一个结构opcodeTable的向量,如下所示:
struct opcodeTableE {
uint16_t opcode;
uint16_t mask;
void (chipCpu::*instruction)(uint16_t);
};
std::vector<opcodeTableE> opcodetable{
{0x00E0, 0xFFFF, chipCpu::clearScreen},
{0x00EE, 0xFFFF, chipCpu::returnFromSub}
};但我得到以下错误:
no instance of constructor "std::vector<_Tp, _Alloc>::vector [with _Tp=chipCpu::opcodeTableE, _Alloc=std::allocator<chipCpu::opcodeTableE>]" matches the argument list -- argument types are: ({...}, {...})注意:我在C++14上
发布于 2018-03-29 22:31:24
您需要使用operator&来获取成员函数的指针。例如:
std::vector<opcodeTableE> opcodetable{
{0x00E0, 0xFFFF, &chipCpu::clearScreen},
{0x00EE, 0xFFFF, &chipCpu::returnFromSub}
};顺便说一句:由于函数到指针的隐式转换,只有在获取指向非成员函数或静态成员函数的指针时,operator&才是可选的。
https://stackoverflow.com/questions/49558697
复制相似问题