fork download
  1. #include <iostream>
  2. #include <assert.h>
  3.  
  4. using namespace std;
  5.  
  6. template<typename T>
  7. struct Array
  8. {
  9. Array(uint32_t w, uint32_t h)
  10. : width(w)
  11. , height(h)
  12. {
  13. buffer = new T[w*h];
  14.  
  15. int k = 0;
  16. for (int i = 0; i < width; i++)
  17. {
  18. for (int j = 0; j < height; j++)
  19. {
  20. buffer[i*height + j] = k++;
  21. }
  22. }
  23. }
  24.  
  25. T get(uint32_t i, uint32_t j) const
  26. {
  27. return buffer[i * height + j];
  28. }
  29.  
  30. private:
  31. T* buffer;
  32. uint32_t width;
  33. uint32_t height;
  34. };
  35.  
  36. #define a[] ()
  37. int main() {
  38. Array<int> a(20, 5);
  39. assert(a.get(0,0) == 0);
  40. assert(a.get(0,5) == 5);
  41. assert(a.get(19,4) == 99);
  42. return 0;
  43. }
Compilation error #stdin compilation error #stdout 0s 3456KB
stdin
Standard input is empty
compilation info
prog.cpp:36:10: warning: ISO C++11 requires whitespace after the macro name
 #define a[] ()
          ^
prog.cpp: In function 'int main()':
prog.cpp:36:10: error: expected unqualified-id before '[' token
 #define a[] ()
          ^
prog.cpp:38:13: note: in expansion of macro 'a'
  Array<int> a(20, 5);
             ^
In file included from prog.cpp:2:0:
prog.cpp: In lambda function:
prog.cpp:39:10: error: expected '{' before '.' token
  assert(a.get(0,0) == 0);
          ^
prog.cpp: In function 'int main()':
prog.cpp:39:11: error: 'struct main()::<lambda()>' has no member named 'get'
  assert(a.get(0,0) == 0);
           ^
prog.cpp: In lambda function:
prog.cpp:40:10: error: expected '{' before '.' token
  assert(a.get(0,5) == 5);
          ^
prog.cpp: In function 'int main()':
prog.cpp:40:11: error: 'struct main()::<lambda()>' has no member named 'get'
  assert(a.get(0,5) == 5);
           ^
prog.cpp: In lambda function:
prog.cpp:41:10: error: expected '{' before '.' token
  assert(a.get(19,4) == 99);
          ^
prog.cpp: In function 'int main()':
prog.cpp:41:11: error: 'struct main()::<lambda()>' has no member named 'get'
  assert(a.get(19,4) == 99);
           ^
stdout
Standard output is empty