为什么会收到C2766:尝试从MFC转换为BCGControlBar

问题描述

我当时使用的是Visual Studio 2017(平台Win10,sdk 10.0.17763.0,unicode),并且没有任何问题地构建此MFC应用程序,但是由于一些MFC错误和BCGControlBar Pro中的增强功能,我决定进行切换。但是,现在我得到了这个奇怪的错误,并且不确定它从哪里来。有人可以在下面看看吗?这是代码:

//-------------------------------
// types
//-------------------------------
typedef uint16_t syscf_t;


//-------------------------------
// templates for hashkey
//-------------------------------
template<>inline UINT AFXAPI HashKey(CString& key) {
  return HashKey((LPCTSTR)key);
}
/************************************************************
\/\/\/\/\/ The Following is the one with the error \/\/\/\/\/
*************************************************************/    
template<>inline UINT AFXAPI HashKey(syscf_t& key) {
  return key;
}

这是错误:

error C2766: explicit specialization; 'UINT HashKey<ARG_KEY>(ARG_KEY)' has already been defined
with
[
    ARG_KEY=TCHAR &
]
c:\program files (x86)\microsoft visual studio\2017\enterprise\vc\tools\msvc\14.16.27023\atlmfc\include\afxtempl.h(160): note: see previous definition of 'HashKey'

双击链接指向:

template<class ARG_KEY>
AFX_INLINE UINT AFXAPI HashKey(ARG_KEY key)
{
    // (algorithm copied from STL hash in xfunctional)
#pragma warning(suppress: 4302) // 'type cast' : truncation
#pragma warning(suppress: 4311) // pointer truncation
    ldiv_t HashVal = ldiv((long)(ARG_KEY)key,127773);
    HashVal.rem = 16807 * HashVal.rem - 2836 * HashVal.quot;
    if (HashVal.rem < 0)
        HashVal.rem += 2147483647;
    return ((UINT)HashVal.rem);
}

更新:

我想我找到了原因,但是不确定如何解决。他们有:

CMap<TCHAR,TCHAR&,int,int> m_mapCharWidth;

在其主头文件的类之一中定义。我的构建没有/ Zc:wchar_t-,因此wchar_t不是特定类型。因此,它必须同时选择两个uint16_t

那么您可以做一个typedef来将类型放在其自己的名称空间中以防止编译器问题吗?

对于它的价值,我尝试过:

namespace testspace
{
  typedef uint16_t syscf_t;
};

template<>inline UINT AFXAPI HashKey(testspace::syscf_t& key) {
  return key;
}

但是它仍然有相同的问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...