Using a variation template as a parameter for a class and method

My question is about the following code snippet:

template <class...T> class A { public: template <class...S> static void a() { } }; template <class...T> class B { public: template <class...S> void b() { A<T...>::a<S...>(); } }; int main(int argc, char** argv) { return 0; } 

I have a class A that has a variational pattern and contains a static method A that has a different variational pattern. From another place (class B in this case) I have two different sets of variation patterns that I want to pass to A::a .

The following error message appears in the compiler (GCC 4.8.1):

  main.cpp: In static member function 'static void B<T>::b()': main.cpp:16:22: error: expected primary-expression before '...' token A <T...>::a<S...>(); ^ main.cpp:16:22: error: expected ';' before '...' token 

Also note that when changing the b() method to this:

  void b() { A<int, char, short>::a<S...>(); } 

or some other template specification A, then the code compiles just fine.

What is wrong with the code above?

+4
source share
1 answer

add template here

 A<T...>::template a<S...>(); 

see comment for reason. In addition, this compiler is beautifully written in VC ++ without a keyword, so I think it depends on the compiler.

+6
source

Source: https://habr.com/ru/post/1493026/


All Articles