I'm trying to create a graph class that is implemented as an array of pointers. This array is dynamically allocated which is where i'm having my trouble. I'm getting an error message from my equal signs saying that the operator doesn't exist

GraphClass::~GraphClass()
{
	Node *temp;
	temp = array;
	Node *temp2;
	temp2 = temp;
	if(array == NULL)
		return;
	else
	{
		for(int i = (arraysize - 1); i >= 0; i--)
		{
			temp2 = temp[i];
			while (temp2!=NULL)
			{
				temp[i] = temp[i].next;
				delete temp2;
				temp2 = temp[i];
			}
		}
	}
}

GraphClass::GraphClass(int k)
{
	int i;
	array = new Node*[k];
	Node *temp = array;
	for(i = 0; i < k; i++)
	{	
		array[i] = NULL;
	}
	arraysize = k;

}

in my class array is a pointer to a Node. like i said i'm getting an error every time i try to use temp...anyone have any ideas?

here are the exact errors i'm getting

C:\Program Files\Microsoft Visual Studio\MyProjects\graphs\GraphClass.cpp(22) : error C2440: '=' : cannot convert from 'struct Node ** ' to 'struct Node *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

C:\Program Files\Microsoft Visual Studio\MyProjects\graphs\GraphClass.cpp(31) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct Node' (or there is no acceptable conversion)

C:\Program Files\Microsoft Visual Studio\MyProjects\graphs\GraphClass.cpp(34) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct Node *' (or there is no acceptable conversion)

C:\Program Files\Microsoft Visual Studio\MyProjects\graphs\GraphClass.cpp(36) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'struct Node' (or there is no acceptable conversion)

C:\Program Files\Microsoft Visual Studio\MyProjects\graphs\GraphClass.cpp(46) : error C2440: 'initializing' : cannot convert from 'struct Node ** ' to 'struct Node *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

You are trying to assign something of type Node** to something of type Node*.

Node *temp;
	temp = array;

Here, you're acting like the value 'array' is of type Node*. But as you've said, it's actually an array of node pointers. (To speak precisely, it's a pointer to an array of node pointers.) This means that array should have type Node**. (I can't see how you've declared it.)

array = new Node*[k];
	Node *temp = array;

Here is a very good example of your problem. The expression new Node*[k] has a return value of type Node** . I don't know what type you've given array , but at any rate, you're trying to assign the value to temp, which is of type Node* .

A typing error such as this indicates you probably have an error in your logic, too.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.