Unordered map: issue using class member function pointer

前端 未结 1 441
一生所求
一生所求 2021-01-16 17:52

I have the following problem: I am writing a simple chip8 emulator, and have a massive class of interpreter functions that I would like to access via opcodes as keys, such a

相关标签:
1条回答
  • 2021-01-16 18:05

    Use std::invoke from the header functional to execute it (C++17):

    test t;
    std::invoke(iter->second, t);
    

    After all, you need to invoke it on an object. The method on its own cannot be executed.

    If you don't have C++17 (IIRC):

    test t;
    (t.*(iter->second))();
    
    0 讨论(0)
提交回复
热议问题