联锁函数 - 无法转换参数

Posted

技术标签:

【中文标题】联锁函数 - 无法转换参数【英文标题】:Interlocked functions - cannot convert arguments 【发布时间】:2015-07-27 07:40:36 【问题描述】:

我需要在 ARM 平台上编译 cppunit。所有在发布模式下编译和工作正常,但在调试模式下我收到以下错误:

Error   1   error C2664: 'unsigned int CppUnit::_InterlockedIncrement(volatile unsigned int *)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *' C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 8959    1   cppunit
Error   2   error C2665: 'CppUnit::_InterlockedIncrement' : none of the 2 overloads could convert all the argument types    C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 8968    1   cppunit
Error   3   error C2664: 'unsigned int CppUnit::_InterlockedDecrement(volatile unsigned int *)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *' C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 8990    1   cppunit
Error   4   error C2665: 'CppUnit::_InterlockedDecrement' : none of the 2 overloads could convert all the argument types    C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 8999    1   cppunit
Error   5   error C2664: 'unsigned int CppUnit::_InterlockedExchange(volatile unsigned int *,unsigned int)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *' C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9024    1   cppunit
Error   6   error C2665: 'CppUnit::_InterlockedExchange' : none of the 2 overloads could convert all the argument types C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9034    1   cppunit
Error   7   error C2664: 'unsigned int CppUnit::_InterlockedExchangeAdd(volatile unsigned int *,unsigned int)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *'  C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9058    1   cppunit
Error   8   error C2664: 'unsigned int CppUnit::_InterlockedExchangeAdd(volatile unsigned int *,unsigned int)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *'  C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9068    1   cppunit
Error   9   error C2665: 'CppUnit::_InterlockedExchangeAdd' : none of the 2 overloads could convert all the argument types  C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9078    1   cppunit
Error   10  error C2665: 'CppUnit::_InterlockedExchangeAdd' : none of the 2 overloads could convert all the argument types  C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9088    1   cppunit
Error   11  error C2664: 'unsigned int CppUnit::_InterlockedCompareExchange(volatile unsigned int *,unsigned int,unsigned int)' : cannot convert argument 1 from 'volatile long *' to 'volatile unsigned int *' C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9123    1   cppunit
Error   12  error C2665: 'CppUnit::_InterlockedCompareExchange' : none of the 2 overloads could convert all the argument types  C:\Program Files (x86)\Windows Phone Kits\8.1\Include\winbase.h 9134    1   cppunit

我已经为此苦苦挣扎了好几天,但我真的找不到任何解决方案。 我正在使用 Visual Studio 2013。

【问题讨论】:

您是否尝试过使用显式强制转换 (static_cast)?由于volatile 被指定用于形式参数和实际参数,这就足够了。 但它适用于 ARM 版本,以及调试和发布 Win32。 【参考方案1】:

遇到同样的事情 - 似乎您是从命名空间内部包含的(在您的情况下为 CppUnit)。编译器不喜欢这样 - 确保您的 #include 在所有命名空间之外。

【讨论】:

以上是关于联锁函数 - 无法转换参数的主要内容,如果未能解决你的问题,请参考以下文章

将函数作为参数传递错误:无法将类型“someType.type”的值转换为预期的参数类型“someType”

为啥 setMouseDown(false) 不能联锁回调函数?

错误 C2664:无法将参数 1 从“int”转换为“int (__cdecl *)(int)”

WaitForSingleObject 与联锁*

无法将“字符串”类型的值转换为预期的参数类型“布尔”

PyQt4 将转换矩阵作为参数传递给构造函数