格式如何写?

解决方案 »

  1.   

    大哥,我问的是如何在类外给这个map添加元素
      

  2.   

    CYourClass::m_yourMap[key] = value.orCYourClass::m_yourMap.SetAt( key, value ).
      

  3.   

    干脆把具体代码写出来class HFileConverse
    {
      //cstring 到 int的映射
     static CMap<CString, LPCTSTR, int, int>  m_maptable;
    }CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable["a"] = 10;编译后出现三个错误:
    error C2057: expected constant expression
    cannot allocate an array of constant size 0
    private: static class CMap<class CString,char const *,int,int>  HFileConverse::m_maptable' : 'class CMap<class CString,char const *,int,int> []' differs in levels of indirection from 'class CMa
    p<class CString,char const *,int,int>'
      

  4.   

    class HFileConverse
    {
     static CMap<CString, LPCTSTR, int, int>  m_maptable;
    }CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable;CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable["a"] = 10;
      

  5.   

    楼上小鸟的写法依旧报错,sigh。TO 薄荷
    初始化难道就不能在全局实现?我不想为了初始化而浪费一个函数
      

  6.   

    o! you shall define m_maptable as public:
    like this;
    class HFileConverse
    {
    public:
     static CMap<CString, LPCTSTR, int, int>  m_maptable;
    }
      

  7.   

    static对象不受任何存储权限的束缚,改为public于事无补
      

  8.   

    i have compile my code.
    yeah, you are right , it wrong.i am sorry.class HFileConverse
    {
    public:
     static CMap<CString, LPCTSTR, int, int>  m_maptable;
    }CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable;// there some wrong with this statement
    //CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable["a"] = 10;
    // but if in a function,no error.
    void f()
    { CMap<CString, LPCTSTR, int, int>  HFileConverse::m_maptable["a"] = 10;}
    i do not know why!but" static对象不受任何存储权限的束缚" is wrong!