compiler gcc4.5 minGW
OS : windows xp sp3

I try something like this

template<typename T, typename U>
class fastRowSum
{

  public :
    fastRowSum();
    typedef void result_type; //what is this line for?
    template<typename inputItr, typename outputItr>
    void operator() (T const VALUE, inputItr ref, outputItr out)
    {     
      error = VALUE > *ref ? VALUE - *ref : *ref - VALUE;
      errorSum += error;    
      std::cout<<"base = "<<VALUE<<", ref = "<<*ref<<", out = "<<*out<<"\n";     
      ++ref; ++out;
    }

  private :
    U error;
    U errorSum;
};

template<typename T, typename U>
fastRowSum<T, U>::fastRowSum()
:error(0),
 errorSum(0)
 {}
//I call the functor like this
std::for_each(augBase.begin(), augBase.end(), std::tr1::bind(fastRowSum<T, U>(), std::tr1::placeholders::_1, augRef.begin(), matchingCost_Itr ) );

after the experiment, I found out that maybe bind didn't really pass the address of
augRef.begin() and matchingCost_Itr to the functor
That is why only the first value of the container would change

++ref; ++out;

didn't increment the address of the iterator

Are there anyway to solve this?Thank you very much

You would need to pass "ref" and "out" by non-const reference. This also means that your call with bind will have to be supplied with non-temporary variables, e.g.:

...
    template<typename inputItr, typename outputItr>
    void operator() (T const VALUE, inputItr& ref, outputItr& out)
...

//I call the functor like this
InputIter augRefItr = augRef.begin(); //get a non-temporary iterator.
std::for_each(augBase.begin(), augBase.end(), std::tr1::bind(fastRowSum<T, U>(), std::tr1::placeholders::_1, augRefItr, matchingCost_Itr ) );
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.