I have written this header file in Eclipse. Eclipse is showing errors that I am not sure what they mean. The code:
is >> numPairs;
kP = new KeyValuePair[numPairs];
Eclipse shows numPairs and kP are not resolved. Then the last two methods (createTable and getValue) shows “Invalid Overload”. I asked my TA about this today and he said the code was correct. I have also tried separating it into an implementation file, but the same errors persist. My header files are in the src folder as well as main.cpp. Is there something I am missing?
#ifndef TRANSLATIONTABLE_H_
#define TRANSLATIONTABLE_H_
#include "KeyValuePair.h"
template<typename Key, typename Value>
class TranslationTable
{
private:
int numPairs;
KeyValuePair<Key,Value> *kP;
public:
TranslationTable(std::istream& is);
TranslationTable();
void createTable(std::istream& is);
Value getValue(Key myKey) const;
};
template<typename Key, typename Value>
TranslationTable<typename Key,typename Value>TranslationTable()
{return;}
template<typename Key, typename Value>
TranslationTable<typename Key,typename Value>TranslationTable(std::istream& is)
{
is >> numPairs;
kP = new KeyValuePair<Key,Value>[numPairs];
}
template<typename Key, typename Value>
void TranslationTable<Key,Value>::createTable(std::istream& is)
{
is >> numPairs;
kP = new KeyValuePair<Key,Value>[numPairs];
}
template<typename Key, typename Value>
Value TranslationTable<Key,Value>::getValue(Key myKey) const
{
}
#endif /* TRANSLATIONTABLE_H_ */
You forgot scope resolution notation
::for constructor definition: