fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<int k>
  5. struct Base{
  6. int a = k;
  7. };
  8.  
  9. struct C1 : Base<1>{};
  10. struct C2 : Base<2>{int b;};
  11.  
  12. typedef Base<1> C1T;
  13.  
  14.  
  15. template<
  16. typename BufferType,
  17.  
  18. typename VerticesType,
  19. VerticesType BufferType::* VerticesField = nullptr
  20. >
  21. void t(){};
  22.  
  23.  
  24. int main() {
  25. // WHY this work??
  26. t<C1T , int, &C1T::a>();
  27.  
  28. // And this not?
  29. C1 c1;
  30. t<C1 , int, &c1::a>();
  31.  
  32. // ok.
  33. // t< Base<1>, int, &Base<1>::a >();
  34.  
  35. // also, ok
  36. t<C2 , int, &C2::b>();
  37. return 0;
  38. }
Compilation error #stdin compilation error #stdout 0s 3292KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:30:1: error: parse error in template argument list
 t<C1 , int, &c1::a>();
 ^
prog.cpp:30:21: error: no matching function for call to ‘t()’
 t<C1 , int, &c1::a>();
                     ^
prog.cpp:30:21: note: candidate is:
prog.cpp:21:10: note: template<class BufferType, class VerticesType, VerticesType BufferType::* VerticesField> void t()
     void t(){};
          ^
prog.cpp:21:10: note:   template argument deduction/substitution failed:
prog.cpp:30:21: error: template argument 3 is invalid
 t<C1 , int, &c1::a>();
                     ^
stdout
Standard output is empty