fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. template<size_t n>
  5. void template_magic(char (&array)[n])
  6. {
  7. cout << "array size: " << n << endl;
  8. }
  9.  
  10. int main()
  11. {
  12. char array[10] = {};
  13. char* pointer = array;
  14. template_magic(pointer);
  15. return 0;
  16. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:14:24: error: no matching function for call to ‘template_magic(char*&)’
  template_magic(pointer);
                        ^
prog.cpp:14:24: note: candidate is:
prog.cpp:5:6: note: template<unsigned int n> void template_magic(char (&)[n])
 void template_magic(char (&array)[n])
      ^
prog.cpp:5:6: note:   template argument deduction/substitution failed:
prog.cpp:14:24: note:   mismatched types ‘char [n]’ and ‘char*’
  template_magic(pointer);
                        ^
stdout
Standard output is empty