c++ - Why does compilation fail when a function template calls a static method template of a class template? -


this question has answer here:

i don't understand why succeeds when calling static method template directly, not when calling through function template.

#include <iostream> #include <type_traits>  template <typename a> class test { public:              template <typename b>     static void test() {         if (std::is_same<a, b>::value)             std::cout << "type , type b same\n";         else             std::cout << "type , type b not same\n";     }        };  template <typename c, typename d> void test() {     test<c>::test<d>(); }  int main(int argc, char* argv[]) {     test<int>::test<int>();     test<int>::test<char>();      test<int, char>();     test<int, int>();      return 0; } 

compiled command line:

g++ -std=c++11 test.cpp 

using:

$ g++ --version g++ (ubuntu 4.9.2-0ubuntu1~14.04) 4.9.2 copyright (c) 2014 free software foundation, inc. free software; see source copying conditions.  there no warranty; not merchantability or fitness particular purpose. 

and got these errors:

test.cpp: in function ‘void test()’: test.cpp:18:20: error: expected primary-expression before ‘>’ token      test<c>::test<d>();                     ^ test.cpp:18:22: error: expected primary-expression before ‘)’ token      test<c>::test<d>();                       ^  

test dependent name here:

template <typename c, typename d> void test() {     test<c>::test<d>();            ^^^^^^^^^ } 

as such, need inform compiler it's template:

template <typename c, typename d> void test() {     test<c>::template test<d>(); } 

Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -