简体   繁体   中英

Unable to compile a functor template

I'm trying to define a function

template<typename Functor> static void start(DataSize size, ThreadNum threadNum, Functor f)
{
    ....

    std::for_each<int>(allocated, size, f);

    ....
}

allocated and size are just int.

The caller calls the function

start(image.width() * image.height(), _threads, RGBHistogramFun<T>(image, hist));

and

template<typename T> class RGBHistogramFun
{
    ...

    void operator()(std::size_t i)
    {
        ....
    }
}

I set T to int for the template. I'm trying to define std::for_each so that it calls RGBHistogramFun::operator(std::size_t i) for each integer from allocated to size. The operator() will use the index to manipulate its internal array data.

However, I'm getting compiler error something about xutility.

n3337 25.2.4

template<class InputIterator, class Function>
Function for_each(InputIterator first, InputIterator last, Function f);

Effects: Applies f to the result of dereferencing every iterator in the range [first,last), starting from first and proceeding to last - 1.

int cannot be dereferenced .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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