diff --git a/CPlusPlus20ForProgrammers-master/examples/shapes/a.out b/CPlusPlus20ForProgrammers-master/examples/shapes/a.out index 0d19890..30deedd 100755 Binary files a/CPlusPlus20ForProgrammers-master/examples/shapes/a.out and b/CPlusPlus20ForProgrammers-master/examples/shapes/a.out differ diff --git a/CPlusPlus20ForProgrammers-master/examples/shapes/shapes.cpp b/CPlusPlus20ForProgrammers-master/examples/shapes/shapes.cpp index 36b8e4e..fd94c2a 100644 --- a/CPlusPlus20ForProgrammers-master/examples/shapes/shapes.cpp +++ b/CPlusPlus20ForProgrammers-master/examples/shapes/shapes.cpp @@ -1,4 +1,5 @@ - +#include +#include /*class GBaseShape { public: GBaseShape(); @@ -19,20 +20,38 @@ double GetVolume() const; class Cube { public: - explicit Cube(double _L = 0, double _W = 0, double _H = 0); + explicit Cube(double _L = 0, double _W = 0, double _H = 0, long int N = 0); + ~Cube(){ + // std::cout << "Destructor was run!\n"; + delete Data; + } // void SetAll(); void SetL(double _L); + // void SetB(double _B); // void SetC(double _C); - + const double& GetL(); + double& operator[] (int i){ + if(i==1) + return L; + if (i==2) + return W; + if (i==3) + return H; + return tmp; + } private: double L,W,H; + double* Data; + double tmp; }; -Cube::Cube(double _L , double _W , double _H ){ +Cube::Cube(double _L , double _W , double _H, long int N ){ SetL(_L); + Data = new double[N]; + //std::cout << "Constructor was run!\n"; } void Cube::SetL(double _L){ @@ -44,9 +63,18 @@ const double& Cube::GetL() { } int main(){ + + Cube cube(5,6,10); + + //cube.GetL()++; + // for (int i{0}; i<10000; i++) + // { + // auto c = Cube(0,0,0,1000000); + // } + //for (int i{0}; i<10000000000; i++) + // std::cout << "!!!\n"; - Cube cube(5); - cube.GetL()++; + std::cout << cube[1] << "\n"; return 0; }