fork download
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. template <typename T, size_t N >
  7. char ( &_ArraySizeHelper( T (&arr)[N] ))[N];
  8. #define countof( arr ) (sizeof( _ArraySizeHelper( arr ) ))
  9.  
  10. template< size_t N >
  11. inline double MyFunction( double (&x)[N] ) {
  12. int M = countof(x);
  13. double s = 0.0;
  14. for ( int i = 0; i < M; i++ ) {
  15. s += x[i];
  16. }
  17. return s;
  18. }
  19.  
  20. template< size_t N >
  21. double BigFunction( double (* PtrFunc)( double (&)[N] ),
  22. const vector<int>& v ) {
  23. int M = v.size();
  24. double x[M];
  25. for( int i = 0; i < M; i++ ) {
  26. x[i] = 1.0;
  27. }
  28. double z = (* PtrFunc)( x );
  29. return z;
  30. }
  31.  
  32. int main() {
  33. vector<int> v;
  34. for(int i = 0; i < 10; i++) {
  35. v.push_back(i);
  36. }
  37. double w = BigFunction< 10 >( &MyFunction, v );
  38. cout << w << endl;
  39. return 0;
  40. }
  41.  
  42.  
Compilation error #stdin compilation error #stdout 0s 3028KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘double BigFunction(double (*)(double (&)[N]), const std::vector<int>&) [with unsigned int N = 10u]’:
prog.cpp:37:50:   required from here
prog.cpp:28:31: error: invalid initialization of reference of type ‘double (&)[10]’ from expression of type ‘double [(((sizetype)(((ssizetype)M) + -1)) + 1)]’
stdout
Standard output is empty