c++ - Using a template function in a template class -


this question has answer here:

i have following (simplified) code:

#include <iostream>  class foo { public:   template<class t>   static size_t f() {     return sizeof(t);   } };  template<class a> class bar { public:   template<class b>   static void f(b const& b) {     std::cout << a::f<b>() << std::endl;   } };  int main() {   bar<foo>::f(3.0);   return 0; } 

it compiles fine in msvc, in gcc (5.2.1) gives following error:

main.cpp:16:26: error: expected primary-expression before ‘>’ token      std::cout << a::f<b>() << std::endl;                           ^ 

(followed few hundred lines of cout-related errors). suppose doesn't realize a::f can template function? breaking in standard?

you need put keyword template:

std::cout << a::template f<b>() << std::endl; 

you need put because a dependent name, otherwise compiler interpret comparison operator:

a::f < b 

Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -