I have three errors:
1) 'KVList::add' : unable to match function definition to an existing declaration
2) 'KVList::replace' : unable to match function definition to an existing declaration
3) 'KVList' : use of class template requires template argument list
Here is my code
KVList.h
template <class K, class V, int N>
class KVList
{
K k[N];
V v[N];
size_t count;
public:
KVList();
size_t size() const;
const K& key(int i) const;
const V& value(int i) const;
KVList& add(const K&, const V&);
int find(const K&k) const;
KVList& replace(int i, const K& kk, const V& vv);
};
KVList.cpp
#include "KVList.h"
template <class K, class V, int N> KVList<K, V, N>::KVList() : count(0)
{
}
template <class K, class V, int N> size_t KVList<K, V, N>::size() const
{
return count;
}
template <class K, class V, int N> const K& KVList<K, V, N>::key(int i) const
{
return k[i];
}
template <class K, class V, int N> const V& KVList<K, V, N>::value(int i) const
{
return v[i];
}
template <class K, class V, int N> KVList& KVList<K, V, N>::add(const K&, const V&)
{
if(count<N)
{
k[count] = kk;
v[count] = vv;
count++;
}
return *this;
}
template <class K, class V, int N> int KVList<K, V, N>::find(const K&k) const
{
for(int ret = 0; ret < count; ret++)
{
if(kk == k[ret])
{
return ret;
}
}
return 0;
}
template <class K, class V, int N> KVList& KVList<K, V, N>::replace(int i, const K& kk, const V& vv)
{
if (i < count)
{
k[i] = kk, v[i] = vv;
}
return *this;
}
Please help (as I have no clue how to fix these three errors as I tried everything)!