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 pass a structure as reference. [modified]

how to pass a structure as reference. [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorial
7 Posts 5 Posters 1 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.
  • U Offline
    U Offline
    uday kiran janaswamy
    wrote on last edited by
    #1

    Hi all, i am facing a problem while passing a reference as structure from one class member function to another class member function. ie) i will pass a struct as input from Class A member function to Class B member function. There in Class B member function it has to fill the Structure and give me the filled structure in Class A member function. Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function. please this very very urgent for me. -- modified at 1:57 Sunday 5th August, 2007

    Uday kiran

    M L B T 4 Replies Last reply
    0
    • U uday kiran janaswamy

      Hi all, i am facing a problem while passing a reference as structure from one class member function to another class member function. ie) i will pass a struct as input from Class A member function to Class B member function. There in Class B member function it has to fill the Structure and give me the filled structure in Class A member function. Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function. please this very very urgent for me. -- modified at 1:57 Sunday 5th August, 2007

      Uday kiran

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Can you show an example of the method declaration and how you were calling it? What exactly is the problem that's occurring? Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • U uday kiran janaswamy

        Hi all, i am facing a problem while passing a reference as structure from one class member function to another class member function. ie) i will pass a struct as input from Class A member function to Class B member function. There in Class B member function it has to fill the Structure and give me the filled structure in Class A member function. Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function. please this very very urgent for me. -- modified at 1:57 Sunday 5th August, 2007

        Uday kiran

        L Offline
        L Offline
        Legolas65
        wrote on last edited by
        #3

        Either you pass the member function a pointer to the structure (&structvar), or make the receiving function accept the argument by reference (classname::member(structtype & structvar).

        U 1 Reply Last reply
        0
        • U uday kiran janaswamy

          Hi all, i am facing a problem while passing a reference as structure from one class member function to another class member function. ie) i will pass a struct as input from Class A member function to Class B member function. There in Class B member function it has to fill the Structure and give me the filled structure in Class A member function. Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function. please this very very urgent for me. -- modified at 1:57 Sunday 5th August, 2007

          Uday kiran

          B Offline
          B Offline
          bob16972
          wrote on last edited by
          #4

          /* Not dialog based but you should get what your looking for here. */ #include "stdafx.h" #include typedef struct { int nKey; int nSize; } MY_STRUCTURE; class CBar { public: CBar::CBar() {} CBar::~CBar() {} void CBar::DoSomething(MY_STRUCTURE& myStructure) { // Modify the structure myStructure.nKey=45; myStructure.nSize=99; } }; class CFoo { public: CFoo() { Start(); } ~CFoo() {} void Start() { CBar bar; MY_STRUCTURE someStructure={0}; printf("BEFORE: nKey = %d, nSize = %d\n", someStructure.nKey,someStructure.nSize); bar.DoSomething(someStructure); printf("AFTER: nKey = %d, nSize = %d\n", someStructure.nKey,someStructure.nSize); } }; int main(int argc, char* argv[]) { CFoo foo; return 0; }

          U 1 Reply Last reply
          0
          • U uday kiran janaswamy

            Hi all, i am facing a problem while passing a reference as structure from one class member function to another class member function. ie) i will pass a struct as input from Class A member function to Class B member function. There in Class B member function it has to fill the Structure and give me the filled structure in Class A member function. Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function. please this very very urgent for me. -- modified at 1:57 Sunday 5th August, 2007

            Uday kiran

            T Offline
            T Offline
            ThatsAlok
            wrote on last edited by
            #5

            uday kiran janaswamy wrote:

            Note: this i am facing in vc++. i am having two dialog classes where i have to send this reference variable from first class member function to second Class member function.

            But what is the problem!.. hang, value is not updated or something else!

            "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

            cheers, Alok Gupta VC Forum Q&A :- I/ IV Support CRY- Child Relief

            1 Reply Last reply
            0
            • B bob16972

              /* Not dialog based but you should get what your looking for here. */ #include "stdafx.h" #include typedef struct { int nKey; int nSize; } MY_STRUCTURE; class CBar { public: CBar::CBar() {} CBar::~CBar() {} void CBar::DoSomething(MY_STRUCTURE& myStructure) { // Modify the structure myStructure.nKey=45; myStructure.nSize=99; } }; class CFoo { public: CFoo() { Start(); } ~CFoo() {} void Start() { CBar bar; MY_STRUCTURE someStructure={0}; printf("BEFORE: nKey = %d, nSize = %d\n", someStructure.nKey,someStructure.nSize); bar.DoSomething(someStructure); printf("AFTER: nKey = %d, nSize = %d\n", someStructure.nKey,someStructure.nSize); } }; int main(int argc, char* argv[]) { CFoo foo; return 0; }

              U Offline
              U Offline
              uday kiran janaswamy
              wrote on last edited by
              #6

              hi, Yes, i cought for this only and you have showed me path. Thanks a Lot it exaclty what the problem i facing.

              Uday kiran

              1 Reply Last reply
              0
              • L Legolas65

                Either you pass the member function a pointer to the structure (&structvar), or make the receiving function accept the argument by reference (classname::member(structtype & structvar).

                U Offline
                U Offline
                uday kiran janaswamy
                wrote on last edited by
                #7

                hi, Thanks a Lot I get it.

                Uday kiran

                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