C ++ explicit template template template template class specification

I have a class like

template <class T>
struct A{
    template <class U>
    A(U u);
};

I would like to write an explicit specialization of this for type declaration

A<int>::A(float);

In the following test code, if I comment on the specialization, it compiles with g ++. Otherwise, it says that I have the wrong number of template parameters:

#include <iostream>

template <class T>
struct A{
    template <class U>
    A(T t, U *u){
        *u += U(t);
    }
};

template <>
template <>
A<int>::A<int,float>(int t, float *u){
    *u += float(2*t);
}

int main(){
    float f = 0;
    int i = 1;
    A<int>(i, &f);
    std::cout << f << std::endl;
    return 0;
}
+5
source share
2 answers

Try

template <>
template <>
A<int>::A(int t, float *u){
     *u += float(2*t);
}

It looks like me.

+4
source

The list of parameters of the definition function must match the declaration.

template <>
template <>
A<int>::A<float>(int t, float *u){
    *u += U(2*t);
}
+1
source

All Articles