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. Easy question about passing by refrence to another function

Easy question about passing by refrence to another function

Scheduled Pinned Locked Moved C / C++ / MFC
questiontutorial
4 Posts 2 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.
  • J Offline
    J Offline
    johnstonsk
    wrote on last edited by
    #1

    I created a stuct in a class and I need a function that returns the pointer to that struct. I need to be able to access the elements in the structure. class MyClass{ struct a { char arr[10]; double dub[10]; } function that returns the pointer to struct a void returnPointer(){ return pointer?????; } } ------------------------- (From another class) MyClass::returnPointer(); a.arr[1]; Do I need to make a struct in the class that is calling the function in order to access the elements by casting the pointer to the struct? As you can see I am a bit lost on how to do this. sj

    A 1 Reply Last reply
    0
    • J johnstonsk

      I created a stuct in a class and I need a function that returns the pointer to that struct. I need to be able to access the elements in the structure. class MyClass{ struct a { char arr[10]; double dub[10]; } function that returns the pointer to struct a void returnPointer(){ return pointer?????; } } ------------------------- (From another class) MyClass::returnPointer(); a.arr[1]; Do I need to make a struct in the class that is calling the function in order to access the elements by casting the pointer to the struct? As you can see I am a bit lost on how to do this. sj

      A Offline
      A Offline
      AlexO
      wrote on last edited by
      #2

      if you asking about syntax struct MyClass::a* returnPointer(){return pointer?????;} if you asking what you should return - you need to declare private/protected member of that type and return pointer to it.

      J 1 Reply Last reply
      0
      • A AlexO

        if you asking about syntax struct MyClass::a* returnPointer(){return pointer?????;} if you asking what you should return - you need to declare private/protected member of that type and return pointer to it.

        J Offline
        J Offline
        johnstonsk
        wrote on last edited by
        #3

        Are you saying that in the class that I call the function from, I need to declare a private struct just like the one in MyClass? Then call the function and cast it to that private struct pointer? thanks, sj

        A 1 Reply Last reply
        0
        • J johnstonsk

          Are you saying that in the class that I call the function from, I need to declare a private struct just like the one in MyClass? Then call the function and cast it to that private struct pointer? thanks, sj

          A Offline
          A Offline
          AlexO
          wrote on last edited by
          #4

          I am not completely sure what you asking. what I meant is : class A { public: typedef struct B{...}B; const B* getMyDatamember() const {return &b;} private: B b; };

          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