Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - structures http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   Structures
   A  structure  is a collection of variables grouped together,  so  that
   they  can  be treated collectively as well as accessed  as  individual
   entities. In C++ a structure may contain function declarations as well
   as  variables.  A C++ structure may have member  functions,  including
   constructors  and destructors. All members of a structure are  public,
   and  the base of a derived structure is always treated as public.

   Defining Structures
   A structure is defined using the keyword struct. The syntax is
   struct tag_name
   {
   data_type variable_name;
   } variable_list;

   where  tag_name  is  an  (optional) tag name  for  the  this  type  of
   structure,  data_type  is  a  basic or  user  defined  data  type  and
   variable_list  is an (optional) comma-separated list of  variables  of
   the struct data type being declared.

   If the tag name is omitted, then at least one object of the  structure
   type  must  be  declared when the struct is defined,  and  it  is  not
   possible to declare further objects of that type later in the program.
   It is good style always to have a tag name so that it is available  to
   the type-safe linkage system.

                        Initialization of Structures
   A  structure can be initialized by following its definition by a  list
   of initial values for the components:

   struct tm a = {0,0,0,1,3.....};

   Individual members of a structure are accessed using the notation
   structure_name.member
   for example:
   struct tm a;

   a.tm_sec = 0;
   a.tm_min = 0;

   In  the same way that we can have a pointer to an int or char, we  can
   also have a pointer to a structure. When using such a pointer there is
   an alternative method of access:

   struct tm *p = &a;


Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson