Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 27th, 2006, 9:57 AM   #1
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
checking str*[] against NULL

When testing if something is NULL does it mean to see if something exists in that memory location, if that is (if not then please do explain) so then why is that am getting an error when i try to see if a struct*[] != NULL. here is the error that i have received.

error C2676: binary '!=' : 'HashTable' does not define this operator or a conversion to a type acceptable to the predefined operator


struct HashTable
{
	int age;
	static HashTable* table[5];
	HashTable* next;
	int createHash(char*, int);
	void insert(int,int);
};
HashTable* HashTable::table[5];

void HashTable::insert(int position, int data)
{
	if((*table)[position] != NULL)//error is on this line
	{
		HashTable* current = new HashTable;
	}

}
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Dec 27th, 2006, 10:28 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You're getting the error because you haven't defined a != operator for a HashTable (which is what your message says, right?). table [position] is a pointer, but if you dereference it, you're referring to a HashTable. You should test the pointer for NULL before you dereference it.

As for NULL, it's implementation defined. There's a good chance it's zero. Every location in memory has something in it. It's a piece of hardware that has bit cells that can only contain the states, 0 and 1 (except for a short period of time when it's transitioning between the two). There is no "nothing"; there's just an agreement that some "something" will represent "nothing".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Dec 27th, 2006, 10:46 AM   #3
kruptof
Professional Programmer
 
kruptof's Avatar
 
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3 kruptof is on a distinguished road
Thanks a bunch Dawei, it worked.

As for the NULL: so instead of checking if its = NULL i can check if it is equal to 0, if so whats the difference between testing if its 0 or NULL;
__________________
Quote:
When I was young it seemed that life was so wonderful,a miracle, oh it was beautiful, magical.
Now watch what you say or they'll be calling you a radical,a liberal, oh fanatical, criminal. Oh won't you sign up your name,we'd like to feel you're acceptable, respectable, oh presentable, a vegetable
kruptof is offline   Reply With Quote
Old Dec 27th, 2006, 10:49 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Your compiler is required to treat zero as if it's NULL, in a pointer context.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
dev c++ software, template problem cairo C++ 11 Jun 2nd, 2006 12:42 PM
Winapi get textbox jayme C++ 6 Jan 16th, 2006 7:02 PM
My first WIN32 API application ivan Show Off Your Open Source Projects 27 Jan 6th, 2006 5:04 PM
Prog hangs when entering new loop... layer C++ 1 May 6th, 2005 6:59 AM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:10 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC