2013-02-06 58 views
-1

我的程序有問題。我正在使用Eclipse,而我一直無法確定這些錯誤的含義。我一直在尋找一段時間,找不到我的錯誤。我在創建文件時附加了兩個顯示錯誤和問題列表的類(我無法在TransitionTable的屏幕截圖中找到#endif語句)。謝謝您的幫助。在Eclipse中找不到錯誤

在第一類中,它給我在構造一個錯誤:

no match for call to `(TranslationTable<int, std::string>) (std::basic_istream<char, std::char_traits<char> >&)' 

#ifndef TRANSLATOR_H_ 
#define TRANSLATOR_H_ 
#include "TranslationTable.h" 
#include <iostream> 
#include <cstdlib> 
#include <fstream> 

template<typename Key, typename Value> 
class Translator 
{ 
    private: 
     TranslationTable<std::string,int> Table1; 
     TranslationTable<int,std::string> Table2; 
     Key getKey(); 
     Value getValue(); 

    public: 
     Translator(); 
     Translator(Key key,Value value); 
     Translator(std::istream& file); 
}; 

template<typename Key, typename Value> 
Translator<Key,Value>::Translator() 
{ 
    return; 
} 

template<typename Key, typename Value> 
Translator<Key,Value>::Translator(std::istream& file) 
{ 
    Table1(file); // gives me error here 
    Table1.fillTable(file); 
    Table2(file); // same error here 
    Table2.fillTable(file); 

} 


#endif /* TRANSLATOR_H_ */ 

這是一個錯誤的第二類,並將其給我一個錯誤將通過陣列循環:

no match for 'operator*' in '**(((TranslationTable<int, std::string>*)this)->TranslationTable<int, std::string>::kP + (+(((unsigned int)i) * 8u)))' 



#ifndef TRANSLATIONTABLE_H_ 
#define TRANSLATIONTABLE_H_ 
#include "KeyValuePair.h" 
#include <iostream> 
#include <cstdlib> 

template<typename Key, typename Value> 
class TranslationTable 
{ 
    private: 
     int numPairs; 
     KeyValuePair<Key,Value> *kP; 

    public: 
     TranslationTable(); 
     TranslationTable(std::istream& is); 
     void fillTable(std::istream& is); 
     Value getValue(Key myKey) const; 
}; 

template<typename Key, typename Value> 
TranslationTable<Key,Value>::TranslationTable() 
{ 
    return; 
} 

template<typename Key, typename Value> 
TranslationTable<Key,Value>::TranslationTable(std::istream& is) 
{ 
    numPairs = 0; 
    is >> numPairs; 
    kP = new KeyValuePair<Key,Value>[numPairs]; 
} 

template<typename Key, typename Value> 
void TranslationTable<Key,Value>::fillTable(std::istream& is) 
{ 
    for(int i = 0; i < numPairs; i++) 
    { 
     is >> *kP[i]; // error here 
    } 
} 

template<typename Key, typename Value> 
Value TranslationTable<Key,Value>::getValue(Key myKey) const 
{ 


} 

#endif /* TRANSLATIONTABLE_H_ */ 
+1

在問題中發佈* actual *錯誤消息和相關代碼。此外,試着總結標題中的問題..有用。如果您*能夠*發現錯誤,您不會問這個問題:D – 2013-02-06 01:43:48

+0

請複製粘貼錯誤本身和代碼(或可能的子集)。顯示我們的波浪線和問題窗口的屏幕截圖,錯誤信息被截斷,最多是令人沮喪的。 –

回答

0

我想你想輸入Translator T1(file);,而不是僅僅T1(file),同樣與T2

而且你不需要**kP[i]。它已經提到了第i個元素。

之後,您需要爲類KeyValuePair定義operator>>以獲得is >> kP[i];的工作。

istream& operator >>(istream &is,KeyValuePair &obj) 
{ 
     ... 
     return is; 
} 
+0

我得到了T1和T2的問題,我做了T1 = TranslationTable (file) ;但是,無論是否使用*,KP都無法工作。 –

+0

@BrentMitchell沒有'*'的錯誤是什麼?缺少'operator >>'? –

+0

對於語句「is >> kP [i]」,它顯示:''中的'operator >>'不匹配'is >> *(((TranslationTable *)this) - > TranslationTable < int,std :: string> :: kP +(+(((unsigned int)i)* 8u)))' –