title: Emulating Classes in C using Structs
body: <p>I am constrained to using C for a competition and I have a need to emulate classes. I am trying to construct a simple "point" class that can return and set the X and Y coordinates of a point. Yet, the below code returns errors such as "unknown type name point", "expected identifier or (" and "expected parameter declarator." What do these errors mean? How do I correct them? Is this the correct approach to writing a "pseudo-class"? </p>
  
  <pre><code>typedef struct object object, *setCoordinates;
  
  struct object {
      float x, y;
      void (*setCoordinates)(object *self, float x, float y);
      void (*getYCoordinate)(object *self);
      void (*getXCoordinate)(object *self);
  };
  
  void object_setCoordinates(object *self, float x, float y){
      self-&gt;x = x;
      self-&gt;y = y;
  }
  
  float object_getXCoordinate(object *self){
      return self-&gt;x;
  }
  
  float object_getYCoordinate(object *self){
      return self-&gt;y;
  }
  
  object point;
  point.setCoordinates = object_setCoordinates;
  point.getYCoordinate = object_getYCoordinate;
  point.getXCoordinate = object_getXCoordinate;
  
  point.setCoordinates(&amp;point, 1, 2);
  printf("Coordinates: X Coordinate: %f, Y Coordinate: %f", point.getXCoordinate, point.getYCoordinate);
  </code></pre>
  
  <p>Reference:
  1. <a href="https://stackoverflow.com/questions/17052443/c-function-inside-struct">C - function inside struct</a>
  2. <a href="https://stackoverflow.com/questions/1403890/how-do-you-implement-a-class-in-c">How do you implement a class in C?</a></p>