fork download
  1. #include <cstddef>
  2.  
  3. #include <iostream>
  4. #include <string>
  5.  
  6. template < typename T >
  7. void myprint( T const *, std::size_t );
  8.  
  9. int main() {
  10. using namespace std;
  11.  
  12. cout << "int array:" << endl;
  13. int ia[] = { 1, 2, 3 };
  14. myprint( ia, 3 );
  15.  
  16. cout << "double array:" << endl;
  17. double da[] = { 1.1, 2.2, 3.3, 4.4 };
  18. myprint( da, 4 );
  19. }
  20.  
  21. // implementation
  22. template < typename T >
  23. void myprint( T const *elems, std::size_t size ) {
  24. for( std::size_t i = 0; i < size; ++i )
  25. std::cout << elems[ i ] << std::endl;
  26. }
  27.  
  28.  
  29. template void myprint<int>( int const *, std::size_t );
  30. template void myprint<double>( double const *, std::size_t );
  31.  
Success #stdin #stdout 0s 2852KB
stdin
Standard input is empty
stdout
int array:
1
2
3
double array:
1.1
2.2
3.3
4.4