函数指针void*加载dlsym(),我可以把它投射到std::function?
假设lib中的函数声明是
int func(int);
using FuncType = std::function<int(int)>;
FuncType f = dlsym(libHandle, "func"); // can this work?
FuncType f = reinterpret_cast<FuncType>(dlsym(libHandle, "func")); // how about this?
Run Code Online (Sandbox Code Playgroud) // since we can dedfine a static array like this
int a[5] = {0};
// decltype(a[5]) is `int [5]`
// Then how about this way?
constexpr int sum(int a, int b) { return a + b; }
int a, b;
std::cin >> a >> b;
int arr[sum(a, b)] = {0};
Run Code Online (Sandbox Code Playgroud)
它可以成功编译,但是是arr一个静态数组?当我尝试arr用typeid().name()或打印类型时boost::typeindex::type_id_with_cvr,我得到以下错误:
error: cannot create type information for type 'int [(<anonymous> + 1)]' because it involves types of variable size
std::cout << typeid(decltype(arr)).name() …Run Code Online (Sandbox Code Playgroud)