I have the following situation:
I have a List class that is using a ListNode class that is inherited in classes that wants to be put in a list.
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.
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.
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 instrusive, dynamic allocations and copying classes is not allowed. Otherwise this would have been solved by creating a container class.