c++ - Default template parameters: Why does the compiler complain about not specifying template argument? -


i have code:

struct a{};  template<class t = a> struct b {     void foo() {} };  b b; //error: missing template arguments before 'b'      //error: expected ';' before 'b'      //more errors b.foo() 

if make foo() template function same template 'signature', compiler doesn't complain not specifying template arguments:

struct {};  struct b {     template<class t = a>     void foo() {} };  b b; //ok b.foo() 

so why need specify argument template class default parameter, not template function? there subtlety missing?

the reason because of template argument deduction failure sure. want know why.

the correct syntax (demo):

b<> b;  

the default argument a assumed class template b. <> part tells compiler b class template , asks take default parameter template argument it.


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -