Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to map CString to Class

How to map CString to Class

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorial
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    ykutanoor
    wrote on last edited by
    #1

    Sir, I am developing an which maps CString as the key and maps to the class. For that I am using this code. in Person.h" CPerson { private: int age; public: CPerson (); CPerson (int a){ age = a; } } And in "FileView.cpp" CMapStringToOb map; CPerson one ; //one = new CPreson(); map.SetAt( "Bart", one ); This gives me an error. Pls help me with a solution . Regards

    C M 2 Replies Last reply
    0
    • Y ykutanoor

      Sir, I am developing an which maps CString as the key and maps to the class. For that I am using this code. in Person.h" CPerson { private: int age; public: CPerson (); CPerson (int a){ age = a; } } And in "FileView.cpp" CMapStringToOb map; CPerson one ; //one = new CPreson(); map.SetAt( "Bart", one ); This gives me an error. Pls help me with a solution . Regards

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      use std::map instead. Then you can do this: myCoolMap["Bart"] = one; I suspect the problem though is that your class needs a copy constructor and/or operator = in order for this to work. Christian I have drunk the cool-aid and found it wan and bitter. - Chris Maunder

      1 Reply Last reply
      0
      • Y ykutanoor

        Sir, I am developing an which maps CString as the key and maps to the class. For that I am using this code. in Person.h" CPerson { private: int age; public: CPerson (); CPerson (int a){ age = a; } } And in "FileView.cpp" CMapStringToOb map; CPerson one ; //one = new CPreson(); map.SetAt( "Bart", one ); This gives me an error. Pls help me with a solution . Regards

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        Either use the template version of CMap (e.g. CMap<CString, LPCTSTR, CPerson*, CPerson*>) in afxtempl.h, or derive CPerson from CObject. Stability. What an interesting concept. -- Chris Maunder

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups