I have the following situation:
I have a List class, made up by class ListNode that is inherited in classes that wants to be put in lists.
Code:
struct _List_node_base
{
void _M_hook(_List_node_base* const __position);
void unhook();
};
template<typename _Tp>
class ListNode : public _List_node_base
{
typedef _Tp* pointer;
public:
pointer GetNext();
pointer GetPrev();
};
template<typename _Tp>
class List
{
...
};
I also have a HashTable class which similar to lists have a HashNode class. The HashNode use ListNode in order to be put in a list in the appropriate hash slot.
Code:
template<typename _KeyType, typename _ObjectType>
class HashNode : public ListNode<ObjectType>
{
public:
_KeyType GetHashKey()
};
template<typename _KeyType, typename _ObjectType, typename _HashFunctionType>
class HashTable
{
//example
template<typename _KeyType, typename _ObjectType, typename _HashFunctionType>
void HashTable<_KeyType, _ObjectType, _HashFunctionType>::Insert(_ObjectType *object)
{
uint pos = hashFunction(object->GetHashKey(), tableSize);
hashTable[pos].PushBack(object);
}
};
I have a class that wants to be both listable and hashable.
Code:
class A : public HashNode<SomeKeyType_t, A>, public ListNode<A>
{
...
};
The problem is that the compiles complains about that the members in _List_node_base has an ambiguous base of class A.
Both in the Hash class and the List class, they use methods in ListNode and _List_node_base directly on class A.
Basically, I want to make class A both hashable and listable but the ListNode functionality of HashNode should not be exposed outside the implementation of class HashTable.
Also the point of the classes are that they must be self contained and not use any dynamic allocation, no copying or allocation are allowed. Otherwise this would have been solved by creating a container class.