c++ - 提示错误:不存在从int转换到CMapPtrToPtr的适当构造函数
问题描述
#include 'StdAfx.h'#include 'CoolControlsManager.h'// If you don’t want to see extra TRACE diagnostics,// modify the line below to: #define CCM_TRACE#define CCM_TRACE TRACE#define CCM_TIMER_VAL 100// 100 ms timer period seems to be good enough...#define MAX_CLASSNAME 64 // Length of buffer for retrieving the class name////////////////////////////////////////////////////////////////////////// CCMControl static members initializationHWND CCoolControlsManager::CCMControl::m_hWndOld = NULL;CMapPtrToPtr CCoolControlsManager::m_ctrlMap = 10;CMapPtrToPtr CCoolControlsManager::m_dlgMap = 10;BOOL CCoolControlsManager::m_bEnabled = true;// Changed 02.03.1999 Mike WalterCMapWordToPtr CCoolControlsManager::m_threadMap = 10; ///////////////////////////////////////////////////////////////////////// Here is the one and only CCoolControlsManager objectstatic CCoolControlsManager g_ctrlManager;CCoolControlsManager& GetCtrlManager(){ return g_ctrlManager;}//CMapPtrToPtr 的定义class CMapPtrToPtr : public CObject{ DECLARE_DYNAMIC(CMapPtrToPtr)protected: // Association struct CAssoc {CAssoc* pNext;void* key;void* value; };public:// Construction //explicitCMapPtrToPtr(INT_PTR nBlockSize = 10);// Attributes // number of elements INT_PTR GetCount() const; INT_PTR GetSize() const; BOOL IsEmpty() const; // Lookup BOOL Lookup(void* key, void*& rValue) const;// Operations // Lookup and add if not there void*& operator[](void* key); // add a new (key, value) pair void SetAt(void* key, void* newValue); // removing existing (key, ?) pair BOOL RemoveKey(void* key); void RemoveAll(); // iterating all (key, value) pairs POSITION GetStartPosition() const; void GetNextAssoc(POSITION& rNextPosition, void*& rKey, void*& rValue) const; // advanced features for derived classes UINT GetHashTableSize() const; void InitHashTable(UINT hashSize, BOOL bAllocNow = TRUE);// Overridables: special non-virtual (see map implementation for details) // Routine used to user-provided hash keys UINT HashKey(void* key) const;// Implementationprotected: CAssoc** m_pHashTable; UINT m_nHashTableSize; INT_PTR m_nCount; CAssoc* m_pFreeList; struct CPlex* m_pBlocks; INT_PTR m_nBlockSize; CAssoc* NewAssoc(); void FreeAssoc(CAssoc*); CAssoc* GetAssocAt(void*, UINT&, UINT&) const;public: ~CMapPtrToPtr();#ifdef _DEBUG void Dump(CDumpContext&) const; void AssertValid() const;#endif void* GetValueAt(void* key) const;protected: // local typedefs for CTypedPtrMap class template typedef void* BASE_KEY; typedef void* BASE_ARG_KEY; typedef void* BASE_VALUE; typedef void* BASE_ARG_VALUE;};//CMapWordToPtr的定义class CMapWordToPtr : public CObject{ DECLARE_DYNAMIC(CMapWordToPtr)protected: // Association struct CAssoc {CAssoc* pNext;void* value;WORD key; };public:// Construction //explicitCMapWordToPtr(INT_PTR nBlockSize = 10);// Attributes // number of elements INT_PTR GetCount() const; INT_PTR GetSize() const; BOOL IsEmpty() const; // Lookup BOOL Lookup(WORD key, void*& rValue) const;// Operations // Lookup and add if not there void*& operator[](WORD key); // add a new (key, value) pair void SetAt(WORD key, void* newValue); // removing existing (key, ?) pair BOOL RemoveKey(WORD key); void RemoveAll(); // iterating all (key, value) pairs POSITION GetStartPosition() const; void GetNextAssoc(POSITION& rNextPosition, WORD& rKey, void*& rValue) const; // advanced features for derived classes UINT GetHashTableSize() const; void InitHashTable(UINT hashSize, BOOL bAllocNow = TRUE);// Overridables: special non-virtual (see map implementation for details) // Routine used to user-provided hash keys UINT HashKey(WORD key) const;// Implementationprotected: CAssoc** m_pHashTable; UINT m_nHashTableSize; INT_PTR m_nCount; CAssoc* m_pFreeList; struct CPlex* m_pBlocks; INT_PTR m_nBlockSize; CAssoc* NewAssoc(); void FreeAssoc(CAssoc*); CAssoc* GetAssocAt(WORD, UINT&, UINT&) const;public: ~CMapWordToPtr();#ifdef _DEBUG void Dump(CDumpContext&) const; void AssertValid() const;#endifprotected: // local typedefs for CTypedPtrMap class template typedef WORD BASE_KEY; typedef WORD BASE_ARG_KEY; typedef void* BASE_VALUE; typedef void* BASE_ARG_VALUE;};
错误提示:
尝试过在定义中将explicit注释掉,但是在保存的时候提示要访问的路径被拒绝,保存不了,请问还有其他的解决方法么
问题解答
回答1:请查看CMapPtrToPtr的定义.CMapPtrToPtr CCoolControlsManager::m_ctrlMap = XXXXX;这一行是让你给CCoolControlsManager::m_ctrlMap这个(静态)变量赋值,m_ctrlMap是CMapPtrToPtr类型的,就只能用同样是CMapPtrToPtr类型的数据来赋值.比如,可以写为CCoolControlsManager::m_ctrlMap = CMapPtrToPtr();//假设CMapPtrToPtr有默认构造函数.总之,CMapPtrToPtr的定义的地方,一般也会提示应该怎么创建它的实例.请查阅一下
相关文章:
1. javascript - 引入 simditor,但是显示标签,这个怎么解决。2. android - 目前有哪些用Vue.js开发移动App的方案?3. 为什么要通过常量的方式拐弯抹角的写呢,直接写DSN之类的不好吗4. python - scrapy获取网页指定内容,后翻到下一页继续,固定循环次数。。问题5. linux - 为公司配置服务器,要求在上面装win7的虚拟机,那我还需要装桌面环境吗?6. defined这个实验代码我这里不对哇7. python 发邮件8. javascript - 网易云信整合到项目的流程9. python删除目录名两端/10. python - 一个关于爬虫的问题