c++ Initialising 2 different iterators in a for loop -


possible duplicate:
can declare variables of different types in initialization of loop?

i'd have loop in c++ constructs 2 different kinds of vector iterator in initialisation.

here rough idea of like:

std::vector<double> dubvec; std::vector<int> intvec; double result = 0;  dubvec.push_back(3.14); intvec.push_back(1);  typedef std::vector<int>::iterator intiter; typedef std::vector<double>::iterator dubiter;  (intiter = intvec.begin(), dubiter j = dubvec.begin(); != intvec.end(); ++i, ++j) {   result += (*i) * (*j); } 

anyone know standard in situation? can't use vector of double intvec because i'm looking general solution. [i.e. might have function f takes int double , calculate f(*i) * (*j)]

you declare std::pair first , second iterator types:

for (std::pair<intiter, dubiter> i(intvec.begin(), dubvec.begin());      i.first != intvec.end() /* && i.second != dubvec.end() */;      ++i.first, ++i.second) {     result += (*i.first) * (*i.second); } 

Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -