[英]C++ Template Iterator error
我正在閱讀我在2006年寫的一些代碼作為本科生。 這是一個使用模板用C ++編寫的簡單遺傳算法庫。 它用於2006年,當我使用visual studio編碼時,但現在當我嘗試在xcode中運行它時,我得到編譯錯誤。
這個函數給了我錯誤:
friend bool operator==(const TSPGenome<T> & t1, const TSPGenome<T> & t2)
{
// loop through each interator and check to see if the two genomes have the same values
if(t1.genome_vec->size() != t2.genome_vec->size())
return false;
else
{
// iterate through each
vector<T>::iterator it_t1;
vector<T>::iterator it_t2;
it_t1 = t1.genome_vec->begin();
for(it_t2 = t2.genome_vec->begin();
it_t2 != t2.genome_vec->end();
++it_t2, ++it_t1)
{
if(*it_t2 != *it_t1)
return false;
}
}
// everything seems good
return true;
}
xcode抱怨這兩行沒有; 在it_t1和it_t2之前。
vector<T>::iterator it_t1;
vector<T>::iterator it_t2;
是因為它的矢量類型T?
我在課堂上宣布如下:
template <typename T>
class TSPGenome : public Genome
{
任何幫助,將不勝感激。
謝謝!
在聲明其類是模板相關類型成員的變量時,請使用typename
:
typename vector<T>::iterator it_t1;
有關typename
關鍵字需求的詳細說明,請參閱C ++ typename
關鍵字的描述 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.