在MFC打开的情况下编译VS2008中的以下代码时出现警告。升压版本1.39如何摆脱在VS2008中由boost :: flyweight产生的C4800警告
include "boost/flyweight.hpp"
include "boost/flyweight/key_value.hpp"
class Foo
{
public:
Foo(const CString& item) : mfoo(item) {}
const CString& getkeyvalue() const {return mfoo;}
private:
const CString mfoo;
};
struct Conversion
{
const CString& operator() (const Foo& item) const {return item.getkeyvalue();}
};
using namespace boost::flyweights;
flyweight<key_value<CString, Foo, Conversion>, tag<Foo> > flyweight_test;
在上面的代码中的最后一行产生警告
d:\工作\源码\ boost1390 \提高\官能\散列\ extensions.hpp(72):警告C4800:'const wchar_t *'
:强制值为bool'true'或'false'(性能警告)
d:\ work \ sourcecode \ boost1390 \ boost \ functional \ hash \ extensions.hpp(71):编译类模板成员函数size_t boost::hash<T>::operator()(const T &) const
与
[
T=ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t>>
]
d:\工作\源码\ boost1390 \升压\ multi_index \ hashedindex.hpp(1159):见参考文献类模板实例 '升压::散列<Ť>' 被与
[
T=ATL::CStringT<wchar_t,StrTraitMFC_DLL<wchar_t>>
编译]
此警告的推移而上,通过散列工厂,MPL等
为什么会出现警告以及如何纠正代码,所以没有警告产生的?
编辑:
要解决,下面添加实施HASH_VALUE
template<typename CharType, typename TraitsType>
std::size_t hash_value(const ATL::CStringT<CharType, TraitsType>& s)
{
return CStringElementTraits<typename TraitsType>::Hash(s);
}
我在我的代码也有类似的警告一次。那里发生了,当我试图用一个const char *(或const wchar_t *在你的情况下)调用一个模板函数并且有多个重载可用时。我想隐式转换为字符串,但编译器选择了转换为bool。 – MP24 2009-10-08 14:17:57
我想知道它是否有助于编译GCC,我记得它很明确地说明问题来自哪里?或者是MFC完全不可行?或者海湾合作委员会不给这个警告? – PJTraill 2016-06-17 12:37:15