搜尋

首頁  >  問答  >  主體

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 initialization

HWND 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 Walter
CMapWordToPtr CCoolControlsManager::m_threadMap = 10;     

///////////////////////////////////////////////////////////////////////
// Here is the one and only CCoolControlsManager object
static 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
    //explicit
        CMapPtrToPtr(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;

// Implementation
protected:
    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
    //explicit
        CMapWordToPtr(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;

// Implementation
protected:
    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;
#endif


protected:
    // 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注释掉,但是在保存的时候提示要访问的路径被拒绝,保存不了,请问还有其他的解决方法么

PHP中文网PHP中文网2806 天前1844

全部回覆(1)我來回復

  • 天蓬老师

    天蓬老师2017-04-17 14:35:49

    請查看CMapPtrToPtr的定義.
    CMapPtrToPtr CCoolControlsManager::m_ctrlMap = XXXXX;
    這一行是讓你給CCoolControlsManager::m_ctrlMap這個(靜態)變數賦值,m_ctrlMap是CMapPtrManager::m_ctrlMap這個(靜態)變數賦值,m_ctrlMap是CMap,ToPtrtrid同樣是CMapPtrToPtr類型的資料來賦值.
    例如,可以寫為
    CCoolControlsManager::m_ctrlMap = CMapPtrToPtr();//假設CMapPtrToPtr有預設建構子.
    總之,CMapPtrToPtr的定義的地方。也會提示該怎麼建立它的實例.請查閱一下

    回覆
    0
  • 取消回覆