fork download
  1. #include <string>
  2. #include <algorithm>
  3.  
  4. class airMap
  5. {
  6. public:
  7. airMap( int, int, int,std::string);
  8. airMap(const airMap& rhs);
  9. airMap& operator=(const airMap& rhs);
  10. ~airMap();
  11.  
  12. private:
  13.  
  14. int dx,dy,dz;
  15. std::string generatorName;
  16. bool*** matrix3D;
  17. void swap(airMap& left, airMap& right)
  18. {
  19. std::swap(left.dx, right.dx);
  20. std::swap(left.dy, right.dy);
  21. std::swap(left.dz, right.dz);
  22. std::swap(left.matrix3D, right.matrix3D);
  23. std::swap(left.generatorName, right.generatorName);
  24. }
  25. };
  26.  
  27. //Constructeurs et destructeurs
  28. airMap::airMap(int x=0,int y=0,int z=0,std::string gen="EMPTY")
  29. {
  30. matrix3D=new bool**[x];
  31. for (int i=0;i<x;i++)
  32. {
  33. matrix3D[i]=new bool*[y];
  34. for (int j=0;j<y;j++)
  35. {
  36. matrix3D[i][j]=new bool[z];
  37. }
  38. }
  39. dx=x;
  40. dy=y;
  41. dz=z;
  42. generatorName=gen;
  43. }
  44.  
  45. airMap::airMap(const airMap& rhs)
  46. {
  47. matrix3D=new bool**[rhs.dx];
  48. for (int i=0;i<rhs.dx;i++)
  49. {
  50. matrix3D[i]=new bool*[rhs.dy];
  51. for (int j=0;j<rhs.dy;j++)
  52. {
  53. matrix3D[i][j]=new bool[rhs.dz];
  54. std::copy(&rhs.matrix3D[i][j][0], &rhs.matrix3D[i][j][0] + rhs.dz,
  55. &matrix3D[i][j][0]);
  56. }
  57. }
  58. dx=rhs.dx;
  59. dy=rhs.dy;
  60. dz=rhs.dz;
  61. generatorName = rhs.generatorName;
  62. }
  63.  
  64. airMap& airMap::operator=(const airMap& rhs)
  65. {
  66. if (&rhs != this)
  67. {
  68. airMap temp(rhs);
  69. swap(temp, *this);
  70. }
  71. return *this;
  72. }
  73.  
  74. airMap::~airMap()
  75. {
  76. for(int i=0;i<dx;i++)
  77. {
  78. for(int j=0;j<dy;j++)
  79. {
  80. delete[] matrix3D[i][j];
  81. }
  82. delete[] matrix3D[i];
  83. }
  84. delete[] matrix3D;
  85. }
  86.  
  87. int main()
  88. {
  89. airMap a1(1,1,1,"abc");
  90. airMap a2 = a1;
  91. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Standard output is empty