title: Function pointer inside a Structure in C
body: <p>I am trying to implement an ArrayList (a dynamic array used in java) using C in Object-Oriented style. I have defined the following struct. (Consider this as a <strong><em>pseudo</em></strong> code)</p>
  
  <pre><code>struct ArrayList{
      /*structure member declarations...
       ...
      */
      void (*add)(); /*function pointer which 
  points to the function which will add a new element at the end of the list*/
  };
  
  /*Function to create an ArrayList "object"*/
  struct ArrayList* newArrayList(){
      /*prepare an ArrayList "object" and return*/
      return arrayList;
  }
  </code></pre>
  
  <p>My question is, is it possible to do something like</p>
  
  <pre><code>struct ArrayList* aL=newArrayList();
  aL-&gt;add(element); /*I want to do it like this*/
  aL-&gt;add(&amp;aL, element); /*And not like this*/
  </code></pre>
  
  <p>I don't want to pass the reference of ArrayList again. 
  I thought of using a <code>static struct ArrayList*</code> variable inside the implementation of add function so that I can initialize it once and it will be used in the subsequent function calls, but then I thought it will create a mess when I create</p>
  
  <pre><code>struct ArrayList* aL2=newArrayList();
  aL2-&gt;add(element); 
  </code></pre>
  
  <p>I know we can write Object-Oriented code in C to some extent. 
  But is it possible to do <code>aL-&gt;add(element);</code> like, the way we access a method in Object-Oriented language? </p>