I'm having problems overloading the index operator with the template class in C ++. I have a custom implementation of the map class, and I need to have access to the elements through the key.
template <typename K, typename DT> DT& myMap<K, DT>::operator[](K key) { for (int i = 0; i<size; i++) { if (elements[i].key == key){ return elements[i].data; } } }
I am trying to overload the operator at the moment. The compiler does not accept the K key to search for data. K is the data type for the key. This is stored in a separate class, which the myMap class contains in the array.
So, if basically I try to do:
myMap<string, int> * test = new myMap < string, int > ; test["car"] = 50;
It says:
Error expression must have an integral or unscoped enum type
I'm not quite sure what the problem is.
Ash m source share