![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
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:
|
|
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 | |
|
Professional Programmer
Join Date: May 2006
Location: UK - London
Posts: 330
Rep Power: 3
![]() |
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:
|
|
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |