fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct Maze {
  5. int id_x;
  6. int id_y;
  7. int north;
  8. int east;
  9. int south;
  10. int west;
  11. };
  12.  
  13. template<size_t N, size_t N2>
  14. void check_consistent(Maze(&maze)[N][N2], int y, int x) {
  15. cout << "idx = " << maze[y][x].id_x << endl;
  16. }
  17.  
  18. int main() {
  19. Maze maze[3][4], maze2[1][1]={777};
  20.  
  21. // init value
  22. int idx=0;
  23. for(unsigned j = 0; j < 3; ++j) {
  24. for(unsigned i = 0; i < 4; ++i) {
  25. maze[j][i] = {idx++};
  26. }
  27. }
  28.  
  29. // check value
  30. check_consistent(maze, 0, 0);
  31. check_consistent(maze, 0, 1);
  32. check_consistent(maze, 1, 0);
  33. check_consistent(maze2, 0, 0);
  34.  
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0s 4556KB
stdin
Standard input is empty
stdout
idx = 0
idx = 1
idx = 4
idx = 777