expected constructor, destructor, or type conversion before '(' token
<p>I am new to programming. I just learned concepts of c++ and some data structures.
I am trying to code a graph representation using adjacency list. 
I am using codeblocks as my compiler. However, whenever I try to compile my program i get the following error...</p>

<p>C:\Users\Garg\Desktop\try\Stack.cpp|22|error: variable or field 'initialize_graph' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|22|error: expected primary-expression before ',' token|
C:\Users\Garg\Desktop\try\Stack.cpp|22|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|23|error: variable or field 'read_graph' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|23|error: expected primary-expression before ',' token|
C:\Users\Garg\Desktop\try\Stack.cpp|23|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|24|error: variable or field 'insert_edge' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|24|error: expected primary-expression before ',' token|
C:\Users\Garg\Desktop\try\Stack.cpp|24|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|24|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|24|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|25|error: variable or field 'print_graph' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|25|error: expected primary-expression before ')' token|
C:\Users\Garg\Desktop\try\Stack.cpp||In function 'int main()':|
C:\Users\Garg\Desktop\try\Stack.cpp|32|error: 'read_graph' was not declared in this scope|
C:\Users\Garg\Desktop\try\Stack.cpp|33|error: 'print_graph' was not declared in this scope|
C:\Users\Garg\Desktop\try\Stack.cpp|36|error: variable or field 'initialize_graph' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|36|error: 'g' was not declared in this scope|
C:\Users\Garg\Desktop\try\Stack.cpp|36|error: expected primary-expression before 'int'|
C:\Users\Garg\Desktop\try\Stack.cpp|46|error: variable or field 'read_graph' declared void|
C:\Users\Garg\Desktop\try\Stack.cpp|46|error: 'g' was not declared in this scope|
C:\Users\Garg\Desktop\try\Stack.cpp|46|error: expected primary-expression before 'int'|
||=== Build finished: 21 errors, 0 warnings ===|</p>

<p>Here is my program:</p>

<pre><code>#include&lt;iostream&gt;
#define MAXV 1000       /* maximum number of vertices */
using namespace std;
struct node
{ 
int y;              /*adjacency info*/
int weight;             /* edge weight, if any */
struct node *next;      /* next edge in list */
} edgenode;

struct graph{
node *edges[MAXV+1];     /* adjacency info */
int degree[MAXV+1];             /* outdegree of each vertex */
int nvertices;          /* number of vertices in graph */
int nedges;             /* number of edges in graph */
int directed;           /* is the graph directed? */
} graph;
void initialize_graph (graph *, int);
void read_graph (graph *, int);
void insert_edge (graph *, int, int, int);
void print_graph (graph *);

int main()
{
struct graph *g = NULL;
cout &lt;&lt; "Now reading graph";
read_graph(g, 1);
print_graph(g);
return 0;
}
void initialize_graph(graph *g, int directed)
{
int i;
g -&gt; nvertices = 0;
g -&gt; nedges = 0;
g -&gt; directed = directed;
for (i=1; i&lt;=MAXV; i++) g-&gt;degree[i] = 0;
for (i=1; i&lt;=MAXV; i++) g-&gt;edges[i] = NULL;
}

void read_graph(graph *g, int directed)
{
int i;
int m;
int x, y;           /* vertices in edge (x,y) */
initialize_graph(g, directed);
cout &lt;&lt; "Enter the number of vertivces and edges";
cin &gt;&gt; g-&gt;nvertices;
cin &gt;&gt; m;
cout &lt;&lt; "Enter the vertices for the edge and the weight of the edge";
for (i=1; i&lt;=m; i++) {
cin &gt;&gt; x;
cin &gt;&gt; y;
insert_edge(g,x,y,directed);
}
}

void insert_edge(graph *g, int x, int y, int directed)
{
struct node *p;
p = malloc(sizeof(struct node));
p-&gt;weight = NULL;
p-&gt;y = y;
p-&gt;next = g-&gt;edges[x];
g-&gt;edges[x] = p; /* insert at head of list */
g-&gt;degree[x] ++;
if (directed == 0)
insert_edge(g,y,x,1);
else
g-&gt;nedges ++;
}



void print_graph(graph *g)
{
int i; /* counter */
edgenode *p; /* temporary pointer */
for (i=1; i&lt;=g-&gt;nvertices; i++) {
cout &lt;&lt; i;
p = g-&gt;edges[i];
while (p != NULL) {
cout &lt;&lt; p-&gt;y;
p = p-&gt;next; 
}
cout &lt;&lt; "\n";
}
}
</code></pre>

<p>Moreover, when i define the functions before main then i get the following result:</p>

<p>C:\Users\Garg\Desktop\try\Stack.cpp|23|error: expected constructor, destructor, or type conversion before '(' token|
C:\Users\Garg\Desktop\try\Stack.cpp|33|error: expected constructor, destructor, or type conversion before '(' token|
||=== Build finished: 2 errors, 0 warnings ===|</p>

<pre><code>#include&lt;iostream&gt;
#define MAXV 1000       /* maximum number of vertices */

using namespace std;

struct node
{
int y;              /*adjacency info*/
int weight;             /* edge weight, if any */
struct node *next;      /* next edge in list */
} edgenode;


struct graph{
node *edges[MAXV+1];     /* adjacency info */
int degree[MAXV+1];             /* outdegree of each vertex */
int nvertices;          /* number of vertices in graph */
int nedges;             /* number of edges in graph */
int directed;           /* is the graph directed? */
} graph;


initialize_graph(graph *g, int directed)
{
int i;
g -&gt; nvertices = 0;
g -&gt; nedges = 0;
g -&gt; directed = directed;
for (i=1; i&lt;=MAXV; i++) g-&gt;degree[i] = 0;
for (i=1; i&lt;=MAXV; i++) g-&gt;edges[i] = NULL;
}

read_graph(graph *g, int directed)
{
int i;
int m;
int x, y;           /* vertices in edge (x,y) */
initialize_graph(g, directed);
cout &lt;&lt; "Enter the number of vertivces and edges";
cin &gt;&gt; g-&gt;nvertices;
cin &gt;&gt; m;
cout &lt;&lt; "Enter the vertices for the edge and the weight of the edge";
for (i=1; i&lt;=m; i++) {
cin &gt;&gt; x;
cin &gt;&gt; y;
insert_edge(g,x,y,directed);
}
}

insert_edge(graph *g, int x, int y, int directed)
{
struct node *p;
p = malloc(sizeof(struct node));
p-&gt;weight = NULL;
p-&gt;y = y;
p-&gt;next = g-&gt;edges[x];
g-&gt;edges[x] = p; /* insert at head of list */
g-&gt;degree[x] ++;
if (directed == 0)
insert_edge(g,y,x,1);
else
g-&gt;nedges ++; 
}



print_graph(graph *g)
{
int i; /* counter */
edgenode *p; /* temporary pointer */
for (i=1; i&lt;=g-&gt;nvertices; i++) {
cout &lt;&lt; i;
p = g-&gt;edges[i];
while (p != NULL) {
cout &lt;&lt; p-&gt;y;
p = p-&gt;next;
}
cout &lt;&lt; "\n";
}
}

int main()
{
struct graph *g = NULL;
cout &lt;&lt; "Now reading graph";
read_graph(g, 1);
print_graph(g);
return 0;
}
</code></pre>

<p>Any pointers to what wrong am I doing?</p>
