晚上好,的std :: unordered_set与自定义分配器
解决方案:这个问题是由明确的关键字来从我的分配器构建函数。
编辑:我终于能够找到问题。它似乎来自unordered_set的移动ctor,当它与一些自定义分配器一起使用时。仍在挖掘。
编辑:奇怪的是,使用我的自定义分配器和std :: vector时没有问题。
为什么我得到一个错误信息,当我尝试的元素从复制:
typedef std::unordered_set< const CScopeProfiler* > CInternalScopeProfilersSet;
到:
typedef std::unordered_set< const CScopeProfiler*, std::hash< const CScopeProfiler* >, std::equal_to< const CScopeProfiler* >, CAllocator< const CScopeProfiler* > > CScopeProfilersSet;
如下:
CProfiler::CScopeProfilersSet CProfiler::ScopeProfilersRegistry() const
{
CScopeProfilersSet kSet;
kSet.insert(*(m_pkRegister->begin()));
return kSet;
}
确切的错误信息用法语给出,所以近似的翻译将是:
Error 1 error C2664: 'std::_Hash<_Traits>::_Hash(const std::_Uhash_compare<_Kty,_Hasher,_Keyeq> &,const GameForge::Core::CAllocator<T> &)' : impossible to convert second parameter of 'std::_Wrap_alloc<_Alloc>' to 'const GameForge::Core::CAllocator<T> &' c:\program files (x86)\microsoft visual studio 11.0\vc\include\unordered_set 195 1
请注意,如果我不把kSet.insert(),我没有得到错误。
typedef在CProfiler的范围内完成。
我一直坚持了几天,它似乎并没有像一个人所期望的那样来自于哈希。任何想法都是值得欢迎的,如果帖子的格式不正确,我很抱歉,因为这是我在StackOverflow上的第一篇文章。
PS:按照要求,这里是代码片段。
namespace GameForge
{
namespace Core
{
class CAllocationsHistogram;
// Ensure profiling code isn't profiled.
class GF_API CProfiler
{
public:
class CScopeRun;
class GF_API CScopeProfiler
{
friend CProfiler;
friend CScopeRun;
public:
CScopeProfiler(const char* pcLabel);
~CScopeProfiler();
};
class GF_API CScopeRun
{
friend CProfiler;
public:
CScopeRun(CScopeProfiler& rkScopeProfiler);
~CScopeRun();
};
typedef std::unordered_set< const CScopeProfiler*,
std::hash< const CScopeProfiler* >,
std::equal_to< const CScopeProfiler* >,
CAllocator< const CScopeProfiler* > > CScopeProfilersSet;
private:
typedef std::unordered_set< const CScopeProfiler* > CInternalScopeProfilersSet;
public:
CScopeProfilersSet ScopeProfilersRegistry() const;
protected:
CProfiler();
~CProfiler();
private:
CInternalScopeProfilersSet* m_pkRegister;
};
我不认为,请发布一个展示此行为的最小完整代码片段。 – 2013-04-29 20:43:07
......重点确实在**最小**代码上。 – 2013-04-29 21:20:40
好吧,因为我不太了解此事,所以发布最小代码非常困难。 – 2013-04-29 21:24:29