I'm starting to play around with C++, coming from C and Objective C (and a bit of Java). I thought a good place to start building my skills is by writing a simple hash table from scratch, using linked lists for collisions. So I started out by writing the skeletons for each class.
class HashTable
{
public:
...
private:
...
};
class LinkedList
{
public:
...
private:
Node *root;
};
class Node
{
public:
Node *next;
string key;
int value;
Node()
{
...
}
};
The weird thing about this is, and this may not come as any surprise to c++ users, that this code wouldn't work. I would get an error like:
error: expected type-specifier before ‘Node’
with respect to the root node in LinkedList class.
When I simply reordered the classes so that it was Node{...}; LinkedList{...}; HashTable{...};
everything worked like a well oiled ice cream truck.
Now, I'm not one to question the design of C++, but is there any reason for this limitation? If I remember correctly, Obj. C's class's are essentially turned into tables and looked up on the fly. So what's reason for this behavior?