Ben*_*uch 0 c++ winapi stdcall unique-ptr visual-c++
我想通过以下方式管理 WinAPI 函数对std::unique_ptr:
#include <memory>
int* __stdcall construct(){ return new int{5}; }
void __stdcall destruct(int* v){ delete v; }
int main() {
using Ptr = std::unique_ptr<int, void(&)(int*)>;
Ptr v(construct(), destruct);
}
Run Code Online (Sandbox Code Playgroud)
当我使用 MSVC 19.33 构建 64 位二进制文件时,代码可以正常工作。如果我构建 32 位二进制文件,则会出现错误。
example.cpp
<source>(8): error C2660: 'std::unique_ptr<int,void (__cdecl &)(int *)>::unique_ptr': function does not take 2 arguments
C:/data/msvc/14.33.31631/include\memory(3291): note: see declaration of 'std::unique_ptr<int,void (__cdecl &)(int *)>::unique_ptr'
Compiler returned: 2
Run Code Online (Sandbox Code Playgroud)
__stdcall如果我明确命名in ,它适用于两者std::unique_ptr<int, void(__stdcall&)(int*)>,所以我假设它是函数签名的一部分。
为什么 32 位和 64 位会有这种差异?这是编译器中的错误吗?
| 归档时间: |
|
| 查看次数: |
87 次 |
| 最近记录: |