2 Replies - 329 Views - Last Post: 09 October 2012 - 06:17 AM Rate Topic: -----

#1 crapmyster  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 12-October 11

I'm getting the error 'next' has incomplete types

Posted 08 October 2012 - 03:18 PM

Hello,

I'm confused as to why I'm getting this error. Could anyone explaine what's going on here?

Thanks,
Mark

#include <iostream>
#include <vector>
using namespace std;
const int hashSize = 100;

class HashNode
{
	public:
		HashNode getNext();
		HashNode getPrevious();
		void setNext(HashNode next);
		void setPrevious(HashNode previous);
		int getKey();
		int getData();	
	private:
		HashNode next;
		HashNode previous;
		int key;
		int data;	
};

HashNode HashNode::getNext()
{
	return next;
}
		
HashNode HashNode::getPrevious()
{
	return previous;
}
		
int HashNode::getData()
{
	return data;
}
		
int HashNode::getKey()
{
	return key;
}
		
void HashNode::setNext(HashNode next)
{
	this->next = next;
}
		
void HashNode::setPrevious(HashNode previous)
{
	this->previous = previous;
}


class HashTable
{
	public: void initialise();
};

void HashTable::initialise()
{
	int HashTable[hashSize];
	for(int i = 0; i < 100; i++)
	{
		vector<int>vec(100);
		HashTable[i] = i;
		vec[i] = HashTable[i];
		cout << HashTable[i] << endl;
		cout << vec[i] << endl;
	}
}

class Menu
{ 
	public: void menu();
};

void Menu::menu()
{
	int temp=0;
	cout << "" << endl;
	cout << "*** Chained HashTable Assignment ***" << endl;
	cout << "Enter a Choice" << endl;
	cout << "Press 'i' to insert an element into the hash table" << endl;
	cout << "Press 'd' to delete an element from the hash table" << endl;
	cout << "Press 'l' to look up an element in the hash table" << endl;
	cout << "Press 's' to obtain the size of the table" << endl;
	cout << "Press 'p' to print the current table" << endl;
	cout << "" << endl;
	int input;
	cin >> input;
	while(temp = 1){
		switch(input)
		{
			case 1: cout << "insert" << endl;		
				break;
			case 2: cout << "delete" << endl;
		        	break;
			case 3: cout << "lookup" << endl;
		        	break;
			case 4: cout << "size" << endl;
				break;
			case 5: cout << "print" << endl;
				break;	
			default:
				cout << "Error: Wrong selection, choose again" << endl;
				temp = 1;
				break;
		}
	}	
}

int main()
{
	Menu m;
	//m.menu();
	HashTable ht;
	ht.initialise();
	return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: I'm getting the error 'next' has incomplete types

#2 NathanMullenax  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 83
  • View blog
  • Posts: 176
  • Joined: 23-September 12

Re: I'm getting the error 'next' has incomplete types

Posted 08 October 2012 - 04:02 PM

HashNode is a value type. Declaring one allocates space for it, so your declaration for HashNode doesn't really make any sense, as it's telling the compiler to allocate two HashNodes for every HashNode ad infinitum. To allocate a hash node, first it would have to determine how many bytes were necessary, which would be 2*sizeof(int)+2*sizeof(HashNode), where sizeof(HashNode) = 2*sizeof(int)+2*sizeof(HashNode), ....

As a general rule, if you aren't using a template class like std::vector to store something that is dynamically allocated, then you'll have to do the memory management explicitly. You probably want next and previous to be HashNode pointers of some kind that are NULL when they haven't yet been allocated.

Of course, whenever you use 'new', you haven't to think about how you are going to delete things. Sorry this is kind of a vague answer, but that's why a class can't contain itself as a class member by value.

Hope this makes sense. My terminology is probably a bit off.
Was This Post Helpful? 1
  • +
  • -

#3 crapmyster  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 71
  • Joined: 12-October 11

Re: I'm getting the error 'next' has incomplete types

Posted 09 October 2012 - 06:17 AM

Okay, thanks for explanation. I sort of got it and changed it accordingly and complied with no errors.

Thanks again!

This post has been edited by crapmyster: 09 October 2012 - 06:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1