Struct member only accessible through pointer to struct.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    Struct member only accessible through pointer to struct.

    Why can I only access a struct member through a pointer to said struct? I thought you were able to access a pointer's members via the dot notation?

    Code:
    person mark;
    person *ptr_mark;
    ptr_mark->age = 1;
    mark.age = 1; /** 'age' undeclared?
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Works for me.

    There is something you aren't telling me.

    Comment

    • Markus
      Recognized Expert Expert
      • Jun 2007
      • 6092

      #3
      What the chuff. I don't understand why it didn't work before, but it works now.

      Sorry!

      Comment

      • Ectara
        New Member
        • Nov 2009
        • 24

        #4
        In the example, the pointer is not initialized, nor is it pointing to the address of the structer declared above it. Though, by your follow-up response, I assume that this isn't an actual code snippet from your project. But otherwise, yeah, lines 3 and 4 would do the same thing if the pointer pointed to the address of the structure.

        Comment

        Working...