1

I have a template struct:

template<typename T2, class, typename, class T3 = vec1<T2> >
struct vec2
{
    template<typename D2, class, typename, class D3>
    void f14(int a);

    template<typename D2, class, typename, class D3>
    void f15(int a);
};

And I want to define, for example function f15. I have no idea, what should I write on the place of the "??". I tried to solve this problem in a different way. But compiler kills my dream to compile my program.

template<typename T2, class , typename , class T3>
template<typename D2, class , typename , class D3>
void vec2<T2,??,??,T3>::f15(int a) {  }

How should I define the function f15?

What is the scientific name for such constructions "class , typename ,"? I googled a lot ("unnamed template parameter", etc...), but I didn't found anything about it. I guess, it alikes the function with unnamed arguments. I would like to read something about it - from C++ standart or from other sources, but I don't know where the necessary information is.

Lucky Man
  • 1,488
  • 3
  • 19
  • 41

1 Answers1

5

You need to name the parameter for the definition.

template <typename T2, class X, typename Y, class T3>
template <typename D2, class X2, typename Y2, class D3>
void vec2<T2, X, Y, T3>::f15<D2, X2, Y2, D3>(int a) {  }

Generally there is no real difference between using typename and class to define a type in the parameter list. The only difference is that when you are defining a template-template argument you must use class.

template <template <typename> class> struct A {};
//                            ^^^^^ class is required here

Moreover, when you are using a dependent type (a type derived from a template argument) you must use typename to define it. It is explained well in this thread.

Community
  • 1
  • 1
David G
  • 94,763
  • 41
  • 167
  • 253
  • I'd add that the reason why you have to name them is: "When you omit the name, you're saying you don't need the parameter for anything. But in this case, you need it - to specify the particular definition. So you cannot omit the name." – Angew is no longer proud of SO Apr 16 '13 at 15:10
  • Does the struct with named template arguments (which have the declarations only) have differences from the struct with unnamed struct arguments, but with defined function f15: template void f15(int a) {}; – Lucky Man Apr 16 '13 at 15:16
  • In other words, if I move the functions definition from such struct/class, etc... with naming of unnamed template arguments, do I break the program's logical structure? – Lucky Man Apr 16 '13 at 15:19
  • Could you link the C++ standart part, where unnamed template parameters are described? – Lucky Man Apr 16 '13 at 15:22
  • @LuckyMan No, you are not changing the logical structure. This is the same as leaving the argument names to a function prototype out, and then naming them when you define them. There is no difference too when it comes to templates. I don't have the standard with me right now, but I will try to look for the appropriate clause when I get one. – David G Apr 16 '13 at 15:42
  • @0x499602D2 Thanks a lot! Your tips were very useful! :) – Lucky Man Apr 16 '13 at 16:02