c++17 std::function 数组,能存储任意函数么?

这是我的代码,可以编译通过,但是core 在了这一行代码里。请问我该如何修改我的代码,让代码运行成功?
原谅我写的这么复杂,项目里有用到这个,之前用的函数指针数组,现在要用clang编译,这个就不通过了,就改为function试试。
clang-14
c++17

ins_func<bool(int)>[1][1](save);
#include <iostream>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define INSTRUCTION_NUM 128
#define DTYPE_NUM 16

bool save(int a)
{
        cout << a << endl;
        cout <<   " hello " << endl;
        return true;
}
template<typename... Args>
std::function<bool(Args...)> ins_func[INSTRUCTION_NUM][DTYPE_NUM];
template <typename T, typename... Args>
bool sum_super_cool(T v, Args... args) {
        cout << "pre" << endl;
        bool ret = ins_func<Args...>[1][1](std::forward<Args>(args)...);
        return ret;
}

int main(int argc, char** argv) {
    cout << "1" << endl;
    ins_func<bool(int)>[1][1](save);
    cout << "2" << endl;
    sum_super_cool(1, 2);

    return 0;
}
阅读 2.2k
1 个回答

ins_func<bool(int)>[1][1](save);
ins_func<int>[1][1] = save;

推荐问题