在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