繁体   English   中英

C ++模板迭代器错误

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM