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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to pass CMap as argument between the functions?

How to pass CMap as argument between the functions?

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelptutorialquestion
7 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.
  • M Offline
    M Offline
    mikert_2008
    wrote on last edited by
    #1

    Hi, I need to fill the CMap map and then Pass it to other function as argument. Is it possible? I am getting error while doing this. e.g CMap<cstring,>, vector >cMapPassArg; -- fill the CMap -- Call the function func(...,..,cMapPassArg) -- Called function func(...,...,CMap cMapPassArg); Mike

    N N 2 Replies Last reply
    0
    • M mikert_2008

      Hi, I need to fill the CMap map and then Pass it to other function as argument. Is it possible? I am getting error while doing this. e.g CMap<cstring,>, vector >cMapPassArg; -- fill the CMap -- Call the function func(...,..,cMapPassArg) -- Called function func(...,...,CMap cMapPassArg); Mike

      N Offline
      N Offline
      Naveen
      wrote on last edited by
      #2

      mikert_2008 wrote:

      I am getting error while doing this.

      This is because there is no copy constructor for CMap. So you cannot pass a CMap object by value. How ever you can pass CMap object either as a pointer or reference. 1) As reference

      func(...,..,cMapPassArg)
      func(...,...,CMap**&** cMapPassArg);

      1. As pointer

      func(...,..,&cMapPassArg)
      func(...,...,CMap***** cMapPassArg);

      nave [OpenedFileFinder] [My Blog]

      1 Reply Last reply
      0
      • M mikert_2008

        Hi, I need to fill the CMap map and then Pass it to other function as argument. Is it possible? I am getting error while doing this. e.g CMap<cstring,>, vector >cMapPassArg; -- fill the CMap -- Call the function func(...,..,cMapPassArg) -- Called function func(...,...,CMap cMapPassArg); Mike

        N Offline
        N Offline
        Nishad S
        wrote on last edited by
        #3

        In this way...

        typedef CMap<CString,LPCTSTR,int,int> MyMap;

        void fun1(MyMap& map)
        {
        }

        void fun2(MyMap* pMap)
        {
        }

        void main()
        {
        MyMap map;
        fun1( map );
        fun2( &map );
        }

        Main point is that when passing template object, the function parameter of template should be of the same template types.

        - ns ami -

        M 1 Reply Last reply
        0
        • N Nishad S

          In this way...

          typedef CMap<CString,LPCTSTR,int,int> MyMap;

          void fun1(MyMap& map)
          {
          }

          void fun2(MyMap* pMap)
          {
          }

          void main()
          {
          MyMap map;
          fun1( map );
          fun2( &map );
          }

          Main point is that when passing template object, the function parameter of template should be of the same template types.

          - ns ami -

          M Offline
          M Offline
          mikert_2008
          wrote on last edited by
          #4

          It's working. Thanks. Mike

          N 1 Reply Last reply
          0
          • M mikert_2008

            It's working. Thanks. Mike

            N Offline
            N Offline
            Nishad S
            wrote on last edited by
            #5

            You are welcome... :)

            - ns ami -

            M 1 Reply Last reply
            0
            • N Nishad S

              You are welcome... :)

              - ns ami -

              M Offline
              M Offline
              mikert_2008
              wrote on last edited by
              #6

              How can CMap Argument be pass to function of two different class? e.g class A { typedef CMap <..,..,..,..>cMyMapA; void func(cMyMapA cMapAgr); } class B { typedef CMap<..,..,..,..>cMyMapB; A objA; objA.func(cMyMapB cMyMapBArg) ????? } Thanks:- Rajiv

              N 1 Reply Last reply
              0
              • M mikert_2008

                How can CMap Argument be pass to function of two different class? e.g class A { typedef CMap <..,..,..,..>cMyMapA; void func(cMyMapA cMapAgr); } class B { typedef CMap<..,..,..,..>cMyMapB; A objA; objA.func(cMyMapB cMyMapBArg) ????? } Thanks:- Rajiv

                N Offline
                N Offline
                Nishad S
                wrote on last edited by
                #7

                You need to declare the typedef available for both classes. It can be in a common header file. For Eg,

                typedef CMap<.....> MyMap;

                class A
                {
                void fun(MyMap& map)
                {
                // use map
                }
                }

                class B
                {
                A m_a;
                MyMap m_map;
                void call()
                {
                m_a.fun(m_map);
                }
                }

                Hope it is clear... :)

                - ns ami -

                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