I separated from a single file into a header and body files, but now have a problem.
I guess I am declaring something wrong but can't figure out what.
Body:
# include "GraphAL.h"
// A utility function to create a new adjacency list node
struct AdjListNode* GraphAL::newAdjListNode(int dest, int weight)
{
struct AdjListNode* newNode =
(struct AdjListNode*) malloc(sizeof(struct AdjListNode));
newNode->dest = dest;
newNode->weight = weight;
newNode->next = NULL;
return newNode;
}
Header:
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
class GraphAL{
public:
struct AdjListNode* newAdjListNode(int dest, int weight);
// A structure to represent a node in adjacency list
struct AdjListNode
{
int dest;
int weight;
struct AdjListNode* next;
};
// A structure to represent an adjacency liat
struct AdjList
{
struct AdjListNode *head; // pointer to head node of list
};
// A structure to represent a graph. A graph is an array of adjacency lists.
// Size of array will be V (number of vertices in graph)
struct Graph
{
int V;
struct AdjList* array;
};
};
The error is: " cannot convert ‘GraphAL::AdjListNode*’ to ‘AdjListNode*’ in return "
struct AdjListNode* newAdjListNode(int dest, int weight);must come after the definition ofstruct AdjListNode. Also the use of malloc causes undefined behaviour, you could usenewinsteadstruct AdjList* array, you can just putAdjList* array