Hi,
I have a very silly problem with the code shown below. The goal is to increment multiple counters at once, and have their value printed after being processed by a provided functor.
However g++ complains :
test.hpp:32: error: expected `;' before 'it' "
I tried to add some typedef, but the error message remains. Here is the code (simplified version of a bigger bunch of code)
#include <vector>
#include <iostream>
template <class F>
class Counter
{
public:
Counter();
void increment(int amount);
private:
F calc;
int current_amount;
};
template <class F>
void Counter<F>::increment(int amount)
{
current_amount += amount;
std::cout << F(amount) << "\n";
}
template <class F>
class CounterBattery
{
public:
CounterBattery();
void incrementAll(int amount);
private:
std::vector<Counter<F> > counters;
};
template <class F>
void CounterBattery<F>::incrementAll(int amount)
{
for (std::vector<Counter<F> >::iterator it = counters.begin() ; it != counters.end() ; it++) // fails to compile here
it->increment(amount);
}
I do not understand what i am doing wrong with templates here.
Thanks for any help you could provide