2013-02-05 39 views
1

我已經在Eclipse中編寫了這個頭文件。 Eclipse顯示錯誤,我不確定它們是什麼意思。代碼:Eclipse中的C++錯誤

是>> numPairs; kP = new KeyValuePair [numPairs];

Eclipse顯示numPairs和kP未解析。然後,最後兩個方法(createTable和getValue)顯示「Invalid Overload」。我今天就此問了我的電訊管理局局長,他說代碼是正確的。我也嘗試將它分離成一個實現文件,但同樣的錯誤仍然存​​在。我的頭文件和main.cpp一樣都在src文件夾中。有什麼我失蹤?

#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_ */ 
+0

你的構造函數的定義(簽名)看起來很奇怪。 '::'在哪裏? – us2012

回答

1

你忘範圍解析符號::的構造函數的定義:

template<typename Key, typename Value> 
TranslationTable<typename Key,typename Value>::TranslationTable() 
               ^^^ 

template<typename Key, typename Value> 
TranslationTable<typename Key,typename Value>::TranslationTable(std::istream& is) 
               ^^^ 
+0

謝謝!這麼簡單的xD – user2041391