C++ Template Iterator error
Posted
by
gprime
on Stack Overflow
See other posts from Stack Overflow
or by gprime
Published on 2010-12-29T20:48:47Z
Indexed on
2010/12/29
20:55 UTC
Read the original article
Hit count: 171
c++
I am going over some code i wrote in 2006 as an undergrad. It's a simple genetic algorithm library written in C++ using templates. It use to work in 2006 when i coded it with visual studio, but now when i am trying to run it in xcode i get compile errors.
This function is giving me errors:
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 complains about these two lines not having ; before it_t1 and it_t2.
vector<T>::iterator it_t1;
vector<T>::iterator it_t2;
Is it because the vector type it T?
I declared it in the class as follows:
template <typename T>
class TSPGenome : public Genome
{
Any help would be appreciated.
Thanks!
© Stack Overflow or respective owner