Thread: How do I access this member?

  1. #1
    Registered User
    Join Date
    Nov 2004
    Posts
    6

    How do I access this member?

    I have something like this:

    Code:
    struct secondStruct {
    
        struct thirdstruct t;
    
    }
    
    struct firstStruct {
    
        secondStruct * s;
    
    }
    So, someone made for me:
    Code:
    firstStruct * f;
    How do I access the value of t?

    I tried doing,
    Code:
    f->s->t
    , but I get an "error: dereferencing pointer to incomplete type". Any help would be appreciated.
    Last edited by Doagie; 10-17-2009 at 02:47 PM. Reason: sorry, not firstStruct->s->t, but f->s->t

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    firstStruct is a type. You want to access actual objects, and your actual object is called f. (Or at least its a pointer to what should be an actual object.)

  3. #3
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Sorry, I mis-typed in my first post. I'm doing
    Code:
    f->s->t
    and it doesn't work. Any ideas?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Do you also have the correct names "struct firstStruct" and "struct secondStruct" in your declarations?

  5. #5
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Yes. Here's an issue: the function I want to call, takes:
    Code:
    myfunction(const struct thirdstruct * a);
    so, I can't call myfunction(f->s->t).

    How do I get the address of the t member so I can pass it in as a pointer?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You use & to get the address of something.

  7. #7
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    I tried doing:

    myfunction(& f->s->t)

    and

    myfunction (&(f->s->t))

    and get the same error. Is there a different syntax I should be using?

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    So did you fix what I mentioned above? This is bad:
    Code:
    struct firstStruct {
    
        secondStruct * s;
    
    }
    This is good:
    Code:
    struct firstStruct {
    
        struct secondStruct * s;
    
    }

  9. #9
    Registered User
    Join Date
    Nov 2004
    Posts
    6
    Hi tabstop,

    It won't be a problem because there is a:

    Code:
    typedef struct secondStructure secondStruct;

    somewhere else, so I think it's valid to call it that way, right?

  10. #10
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Probably, except you're getting errors. So what are the errors, then?

  11. #11
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,059
    Post the code snippet that is giving errors.

    Is firstStruct a typedef too? If not f should be declared as
    Code:
    struct firstStruct *f;
    And how is struct thirdstruct t declared?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. file reading
    By gunghomiller in forum C++ Programming
    Replies: 9
    Last Post: 08-07-2007, 10:55 PM
  2. New to C++ Classes
    By Cypher in forum C++ Programming
    Replies: 122
    Last Post: 07-05-2007, 01:49 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Static & Data Member
    By ecoliteracy in forum C++ Programming
    Replies: 1
    Last Post: 04-16-2007, 08:46 PM
  5. class member access denied
    By chiqui in forum C++ Programming
    Replies: 2
    Last Post: 05-27-2002, 02:02 PM

Tags for this Thread