pointers as members of classes

This is a discussion on pointers as members of classes within the C++ Programming forums, part of the General Programming Boards category; alright, here's my problem... Code: struct STRUCT1 { STRUCT2* pStruct2; } struct STRUCT2 { int stuffINeed; } int main() { ...

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    83

    pointers as members of classes

    alright, here's my problem...
    Code:
    struct STRUCT1
    {
            STRUCT2* pStruct2;
    }
    
    struct STRUCT2
    {
            int stuffINeed;
    }
    
    int main()
    {
          STRUCT1 someStruct;
          STRUCT2 someOtherStruct;
    
          someStruct.pStruct2.stuffINeed = 5;
    how do I access stuffINeed from the pointer?
    someStruct.*pStruct2.stuffINeed doesnt work. Can you guys help me out?
    This isn't my exact problem, but like my project is way to complicated to post source code

  2. #2
    Registered User Red Haze's Avatar
    Join Date
    Nov 2003
    Posts
    30
    You can either try:

    (*someStruct.pStruct2).stuffINeed = 5;

    Or even simpler:

    someStruct.pStruct2->stuffINeed = 5;
    ----[Red Haze]----

  3. #3
    Registered User
    Join Date
    Oct 2003
    Posts
    83
    Dude! That's just what I was looking for! It works great! I didn't think I would get a reply cuz it was so confusing. Thanks a lot man!

    I'm still having problems with my project.. Maybe I'll post the source sometime and let you guys take a look at it

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointers to (templated) classes being declared
    By reanimated in forum C++ Programming
    Replies: 2
    Last Post: 01-02-2006, 08:30 AM
  2. Pointers to Classes || pointers to structures
    By C++Child in forum C++ Programming
    Replies: 24
    Last Post: 07-30-2004, 06:14 PM
  3. function pointers in c++ classes
    By optimism_ in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2002, 02:35 PM
  4. Pointers to classes
    By Unregistered in forum C++ Programming
    Replies: 11
    Last Post: 06-02-2002, 09:25 PM
  5. question time (classes and pointers)
    By swarm in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2002, 10:33 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21