This is a simple matter of understanding what structures are.
Take, for example, a structure of
student
. You want student to represent all data relevant to, what(?): A Student. So, what is a student? Well, we need a name, we need any other relevant information. If we were to pass this stuff to functions whenever we needed it, it would be a vortex of entropy. A better way to group such data (and a much more easily managable way) is to gather it into object-like constructs that represent the data as a group.
So, knowing this, we need to apply syntax to it.
You clearly don;t understand what a member function is: a member function of a structure, or class, is declared directly in that structure or class.
Example:
1 2 3 4 5
|
struct student{
char first_name[20], last_name[20], middle_initial;
int year;
};
|
So, here we have a data structure. We 'named' it
student
. So, what are the members? Well, they are clearly declared: there is
first_name
,
last_name
,
middle_initial
, and
year
. When we want to access a member function through an instance of a structure, we can use the following syntax:
1 2 3 4
|
student a_single_student;
//what is the name of this student??
cout<< a_sing_student.first_name<< endl; //psuedocode, I don't work with arrays too often
|
here, we reference a member function of and instance of student called
a_single_student
, and we called a member variable of the structure called
first_name
. Note that whenever we call a member, the entire object can be treated as whatever member you're calling (so if you are referencing an array, and can use the .operator[]() on it, and it will reference the index of the array, etc...), although somtimes you may need parentheses to clarify for the compiler what you're refering to (look up operator precedence). Try not to do this too much at your level, I do a lot of 1-liners because of this, lol.
So, I hope you better understand data structures. You will be working with much much more complicated objects in the future (if you're CS major, that is), and it is impairative you understand these basic things.
Hope this helps, let me know if you need any more help. Pardon any mistakes, as it's nearly midnight for me...