为 std::function 设置调用约定
Setting a calling convention for std::function
我对使用 std 很陌生,我目前正在尝试调用一个将 std::function 作为参数的函数。类似于以下内容:
在一个库的 .h 文件中:
typedef bool t (/*Params*/);
void __stdcall Foo(std::function<t> &function) {m_function = function;}
std::function<t> m_function;
我导入了库并尝试在另一个 cpp 文件中使用 Foo:
bool Implementation (/*Params*/)
{
// Implementation
}
void Bar()
{
Foo(std::function<t> (Implementation));
}
由于调用约定,我在为 x86(但不是 x64)编译时收到链接器错误 (LNK2019):
Unresolved External Symbol __stdcall Foo (class std::tr1::function<bool __cdecl(/*Params*/) const&)
由此我了解到我需要将"t"和实现标记为__stdcall但这样做会导致其他编译失败。我还应该注意在同一个库中构建代码时正确编译的代码。有没有办法将调用约定与 std::function 相关联?
尝试:
void Foo(const std::function<bool()> &func)
{
func();
}
bool Implementation (/*Params*/)
{
cout << "Implementation"<<endl;
return true;
}
void Bar()
{
Foo(std::function<bool()>(&Implementation));
}
int main()
{
Bar();
return 0;
}
相关文章:
- 为什么在 x64 中忽略__stdcall调用约定?
- 窗口调用约定
- 我应该提到纯虚函数中的调用约定吗?
- 如何使用gcc指定stdcall调用约定
- Clang:x86 FPU调用约定
- 该标准是否说明了例外和不同调用约定的共存
- Clang++的InterlockedExchange的32位调用约定错误,但MSVC可以
- std::sort & comp - 调用约定?
- 如何为类 /块 /范围选择C 调用约定
- DLL 的"good"调用约定是什么?
- 结构中重载运算符的调用约定
- 'ShowSUM':__declspec(dllexport)不能应用于具有__clrcall调用约定的函数
- x86-64 调用约定中的返回值
- 内联功能和调用约定
- 正在直接显示筛选器中调用约定
- 何时使用`__fastcall`调用约定
- 为C++结构定义显式析构函数如何影响调用约定
- 由于使用 MFC 时"__cdecl"和"__thiscall"调用约定不匹配而导致的链接器错误?
- Microsoft Visual C++是否未使用带有浮点的C/C++调用约定
- 在Visual Studio中调用约定