title: Usage of malloc in graph program
body: <p>I have following code for creating a graph structure using adjacent list</p>
  
  <pre><code>#include&lt;iostream&gt;
  #include&lt;algorithm&gt;
  #include&lt;string.h&gt;
  #include&lt;math.h&gt;
  #include&lt;iostream&gt;
  using namespace std;
  #define MAX 1000
  
  typedef struct {
      int y;
      int weight;
      struct edgenode *next;
      }edgenode;
  
  typedef struct
  {
      edgenode* edges[MAX+1];
      int degree[MAX+1];
      int nvertices;
      int ndegrees;
      int nedges;
      bool directed;
      }graph;
  
  void initialize(graph *g,bool directed){
      int i;
      g-&gt;nvertices=0;
      g-&gt;nedges=0;
      g-&gt;directed=directed;
      for(i=1;i&lt;=MAX;i++)g-&gt;degree[i]=0;
      for(i=1;i&lt;=MAX;i++)g-&gt;edges[i]=NULL;
  }
  
  void insert(graph *g,int x,int y,bool directed){
      edgenode *p;
      p=malloc(sizeof(edgenode));
  }
  
  int main(){
      return 0;
  }
  </code></pre>
  
  <p>When I try to compile it, I get the following error:</p>
  
  <pre><code>1&gt;------ Build started: Project: graph_list, Configuration: Debug Win32 ------
  1&gt;  graph_list.cpp
  1&gt;c:\users\dato\documents\visual studio 2010\projects\graph_list\graph_list\graph_list.cpp(12): error C2371: 'edgenode' : redefinition; different basic types
  1&gt;          c:\users\dato\documents\visual studio 2010\projects\graph_list\graph_list\graph_list.cpp(11) : see declaration of 'edgenode'
  1&gt;c:\users\dato\documents\visual studio 2010\projects\graph_list\graph_list\graph_list.cpp(35): 
  
  error C2027: use of undefined type 'edgenode'
  1&gt;          c:\users\dato\documents\visual studio 2010\projects\graph_list\graph_list\graph_list.cpp(11) : see declaration of 'edgenode'
  1&gt;c:\users\dato\documents\visual studio 2010\projects\graph_list\graph_list\graph_list.cpp(35): error C2440: '=' : cannot convert from 'void *' to 'edgenode *'
  1&gt;          Conversion from 'void*' to pointer to non-'void' requires an explicit cast
  ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p>What am I doing wrong and how can I fix it?</p>