next up previous
Next: When do I use Up: class and struct Previous: class and struct

How do I use class and struct?

A C++ struct (or class) is almost like a struct in C (i.e. a set of attributes), but has two additional kinds of members: methods and data types. A class' method has to be used with an instance of that class. The important is that methods have always access to their instance's attributes and data types.
struct A
{
  typedef char  t_byte; // type
  unsigned char i;      // attribute
  void          m()     // method
  {
    t_byte      b = 1;  // m can access type t_byte

    i = b;              // m can access attribute i
  }
};

void	function()
{
  A     a;

  a.m();               // an instance is required to call a method.
}



Alexis Angelidis (PhD) 2005-01-11