Operator Specialization ()

I am trying to specialize for a template operator, the template is as follows:

 template <typename Iterator1, typename Iterator2>
ResultType operator()(Iterator1 a, Iterator2 b, size_t size, ResultType worst_dist = -1) const

after I made a specialization that looks like this:

template <>
float operator()<float*,float*>(float* a, float const* b, unsigned long size, float worst_dist = -1) const

I get an error at compile time:

Cannot specialize function 'operator ()' within class

All these functions are in the structure template.

I will be happy to receive help. thank.

+5
source share
1 answer

? , (.. [] ) ! , . , , , , .

, . :

#include <iostream>

struct foo
{
    template <typename T> void operator()(T const&) {
        std::cout << "general\n";
    }
};

template <>
void foo::operator()<int>(int const&) {
    std::cout << "int spec\n";
}

int main()
{
    foo f;
    f(1.2);
    f(1);
    f<double>(1); // <-- ERROR: doesn't work!
}

, . .

+7

All Articles