Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;:[VS2010]:警告C4396:&x27;stdext::散列值';:当执行友元声明时,不能使用内联说明符 我将VS2005 C++代码转换成VS2010代码。不幸的是,在VS2010中,它给出了编译器警告,而在VS2005中,它编译得很顺利。(仅供参考:我已将警告设置为错误)_C++ - Fatal编程技术网

C++;:[VS2010]:警告C4396:&x27;stdext::散列值';:当执行友元声明时,不能使用内联说明符 我将VS2005 C++代码转换成VS2010代码。不幸的是,在VS2010中,它给出了编译器警告,而在VS2005中,它编译得很顺利。(仅供参考:我已将警告设置为错误)

C++;:[VS2010]:警告C4396:&x27;stdext::散列值';:当执行友元声明时,不能使用内联说明符 我将VS2005 C++代码转换成VS2010代码。不幸的是,在VS2010中,它给出了编译器警告,而在VS2005中,它编译得很顺利。(仅供参考:我已将警告设置为错误),c++,C++,请看一下代码片段: 错误出现在友元声明所在的行 class __declspec(dllexport) MyKey { friend size_t stdext::hash_value<MyKey>(const MyKey& key); // compiler warning at this line (pls see below for the actual compiler warning) ubit32 m_uKey1; }; template&

请看一下代码片段:

错误出现在友元声明所在的行

class __declspec(dllexport) MyKey
{
    friend size_t stdext::hash_value<MyKey>(const MyKey& key);  // compiler warning at this line (pls see below for the actual compiler warning)

    ubit32  m_uKey1;

};
template<> inline size_t stdext::hash_value<MyKey>(const MyKey& key)
{
    return key.m_uKey1;
}

请帮我解决这个错误。谢谢。

我通过在MyKey的类声明之前添加以下两个转发声明语句得到了修复

class MyKey;

template<> size_t stdext::hash_value<MyKey>(const MyKey& key);
类MyKey;
模板大小stdext::散列值(constmykey&key);

现在错误/警告消失了。我做得对吗?

我通过在MyKey的类声明之前添加以下两个前向声明语句得到了修复

class MyKey;

template<> size_t stdext::hash_value<MyKey>(const MyKey& key);
类MyKey;
模板大小stdext::散列值(constmykey&key);

现在错误/警告消失了。我做得对吗?

由于您的好友声明没有内联的
说明符,这显然是MSVC编译器中的一个错误。可以使用编译器选项或pragma抑制警告:

#pragma warning(disable: 4396)

由于您的friend声明没有
inline
说明符,这显然是MSVC编译器中的一个错误。可以使用编译器选项或pragma抑制警告:

#pragma warning(disable: 4396)

您不了解警告的哪一部分?@CodyGray:如何修复它?如果从“模板内联大小stdext::hash_值(const MyKey&key)”中删除内联,会发生什么情况?stdext::has_值的声明是什么?在
友人
声明之前是否可用?真正的
friend
声明是否与问题中所示完全一致?(即,
friend
声明中没有
inline
,是吗?)如果我从“模板内联大小stdext::hash_值(const MyKey&key)”中删除内联,我仍然会出错。stdext::hash_值的原始实现位于文件中,如下模板内联大小hash_值(const_Kty&u Keyval){//hash_Keyval to size_t value一对一返回((size_t)_Keyval^ u hash_SEED)}请帮助我如何修复它。您不明白警告的哪一部分?@CodyGray:如何修复它?如果从“模板内联大小stdext::hash_value(const MyKey&key)”中删除内联,会发生什么情况
stdext::has_value
主模板的声明是什么?在
friend
声明之前是否可用?真正的
friend
声明是否与问题中所示完全相同?(即
friend
声明中没有
内联
,是吗?)如果我从“模板内联大小stdext::hash_值(const MyKey&key)”中删除内联,我仍然会出错。stdext::hash_值的原始实现在文件中,如下所示:模板内联大小散列值(const_Kty&_Keyval){//hash_Keyval to size_t值一对一返回((size_t)_Keyval^ _hash_SEED)}所以,请帮助我如何修复它。