cari

Rumah  >  Soal Jawab  >  teks badan

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中文网2803 hari yang lalu1839

membalas semua(1)saya akan balas

  • 天蓬老师

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

    请查看CMapPtrToPtr的定义.
    CMapPtrToPtr CCoolControlsManager::m_ctrlMap = XXXXX;
    这一行是让你给CCoolControlsManager::m_ctrlMap这个(静态)变量赋值,m_ctrlMap是CMapPtrToPtr类型的,就只能用同样是CMapPtrToPtr类型的数据来赋值.
    比如,可以写为
    CCoolControlsManager::m_ctrlMap = CMapPtrToPtr();//假设CMapPtrToPtr有默认构造函数.
    总之,CMapPtrToPtr的定义的地方,一般也会提示应该怎么创建它的实例.请查阅一下

    balas
    0
  • Batalbalas