Hello folks,
I've had this warning (that creeps up to an error) multiple times and I thought I finally had templates ingrained in my brain so that it would never come back to haunt me again, but unfortunately it has...
Here's my class definition:
Code:
template <typename T>
class OAHashTable
{
public:
// Slots that will hold the key/data pairs
struct OAHTSlot
{
char Key[MAX_KEYLEN]; // Key is a string
T Data; // Client data
enum OAHTSlot_State {OCCUPIED, UNOCCUPIED, DELETED};
OAHTSlot_State State;
};
OAHashTable(const OAHTConfig& Config);
~OAHashTable();
// Insert a key/data pair into table. Throws an exception if the
// insertion is unsuccessful.
void insert(const char *Key, const T& Data) throw(OAHashTableException);
// Delete an item by key. Throws an exception if the key doesn't exist.
// Adjusts the table by moving key/data pairs, if necessary
void remove(const char *Key) throw(OAHashTableException);
// Find and return data. Throws an exception if the key doesn't exist.
T& find(const char *Key) const throw(OAHashTableException);
// Removes all items from the table (Doesn't deallocate table)
void clear(void);
OAHTStats GetStats(void) const;
const OAHTSlot *GetTable(void) const;
private:
// Private fields and methods
};
And here's the class function I'm having trouble with.
Code:
template <typename T>
const OAHashTable<T>::OAHTSlot* OAHashTable<T>::GetTable(void) const
{
}
There's something wrong with the the way I'm defining the function in my .cpp because Visual Studios 2005 tells me that
Code:
Warning 1 warning C4346: 'OAHashTable<T>::OAHTSlot' : dependent name is not a type
Error 2 error C2143: syntax error : missing ';' before '*'
Error 3 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I believe the errors are a trickle down effect from the warning but I can't figure out what I'm doing wrong. I know it has to do with the way I'm defining the * to the struct that I'm returning but through all my mixing and matching of trying to get the definition correct I've not yet stumbled upon the correct form.
I looked through a couple template websites, searched for the C4346 warning, and now I find myself here. I hope someone can lead me in the right direction.
Thanks in advance,
-Peter