Connecting Tech Pros Worldwide Help | Site Map

Struct member only accessible through pointer to struct.

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#1: 3 Weeks Ago
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?

Expand|Select|Wrap|Line Numbers
  1. person mark;
  2. person *ptr_mark;
  3. ptr_mark->age = 1;
  4. mark.age = 1; /** 'age' undeclared?
  5.  
Moderator
 
Join Date: Mar 2007
Location: North Bend Washington USA
Posts: 5,366
#2: 3 Weeks Ago

re: Struct member only accessible through pointer to struct.


Works for me.

There is something you aren't telling me.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#3: 3 Weeks Ago

re: Struct member only accessible through pointer to struct.


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

Sorry!
Newbie
 
Join Date: Nov 2009
Posts: 20
#4: 3 Weeks Ago

re: Struct member only accessible through pointer to struct.


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.
Reply