Advertisement
avr39ripe

Pv913ThisProofOfLifeOnMars :)

May 20th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. class Test
  4. {
  5.     static int common;
  6.     int x;
  7.     float y;
  8.     int* ptr;
  9.     static const int size{42};
  10.  
  11. public:
  12.    
  13.     Test() : Test(0) { std::cout << "Default constructor for Test\n"; };
  14.     Test(int pX, int pSize = 433) : x{ pX }, ptr{ new int[10] }, y{ 36.6} {++common; std::cout << "Test constructed for " << this << '\n' << "This is #" << common << " instance of Test\n"; }
  15.     ~Test() { delete[] ptr; std::cout << "Test destructed for " << this << '\n' << "This was #" << common-- << " instance of Test\n"; };
  16.     void setX(int x) { this->x = x; std::cout << "in setX this is: " << this << '\n'; };
  17.     int getX() { std::cout << "in getX this is: " << this << '\n'; return this->x; };
  18.     void setY(int y) { this->y = y; std::cout << "in setY this is: " << this << '\n'; };
  19.     int getY() { std::cout << "in getY this is: " << this << '\n'; return this->y; };
  20.     int getSize() { return size; };
  21.     bool isEqual(Test* const obj) { return (obj == this); };
  22.     Test& add(int num) { x += num; std::cout << "in add this is: " << this << '\n'; return *this; };
  23.     Test& sub(int num) { x -= num; std::cout << "in sub this is: " << this << '\n'; return *this; };
  24.     Test& mul(int num) { x *= num; std::cout << "in mul this is: " << this << '\n'; return *this; };
  25.     Test& div(int num) { x /= num; std::cout << "in div this is: " << this << '\n'; return *this; };
  26.     static int getObjCount(){ return common; };
  27.     static void sayName() { std::cout << "I'm a Test class!\n"; };
  28. };
  29.  
  30. //int getXTest(Test* const obj) { return obj->x; };
  31.  
  32. int Test::common{0};
  33.  
  34. int cnt()
  35. {
  36.     static int cntNum{ 55 };
  37.     return ++cntNum;
  38. }
  39.  
  40.  
  41. //Test* const this; //1
  42. //const Test* this; //2
  43.  
  44. int main()
  45. {
  46.  
  47.     //for (int i{ 0 }; i < 5; ++i)
  48.     //{
  49.     //  std::cout << cnt() << '\n';
  50.     //};
  51.  
  52.     //std::cout << Test::common << '\n';
  53.     //Test::common = 888;
  54.     //std::cout << Test::common << '\n';
  55.     //std::cout << "There are " << Test::getObjCount() << " objects of Test class \n";
  56.     //std::cout << "\n\n";
  57.     Test anotherTest{ 678, 55 }; //anotherTest.x anotherTest.ptr
  58.     //std::cout << "\n\n";
  59.     //std::cout << "There are " << anotherTest.getObjCount() << " objects of Test class \n";
  60.    
  61.     Test newTest{ 212 }; //newTest.x newTest.ptr
  62.     //std::cout << "\n\n";
  63.     //std::cout << "There are " << myTest.getObjCount() << " objects of Test class \n";
  64.  
  65.     //std::cout << "We got mytest up and running!\n";
  66.     //myTest.setX(42);
  67.     //std::cout << myTest.getX() << '\n';
  68.     //std::cout << myTest.getX() << '\n';
  69.     //std::cout << anotherTest.getX() << '\n';
  70.  
  71.     //std::cout << myTest.isEqual(&myTest) << '\n'; //1
  72.     //std::cout << myTest.isEqual(&anotherTest) << '\n'; //0
  73.     //std::cout << myTest.isEqual(&newTest) << '\n'; //0
  74.  
  75.     //std::cout << anotherTest.isEqual(&anotherTest) << '\n'; //1
  76.     //std::cout << anotherTest.isEqual(&myTest) << '\n'; //0
  77.     //std::cout << anotherTest.isEqual(&newTest) << '\n'; //0
  78.  
  79.     //std::cout << myTest.getSize() << '\n';
  80.     //std::cout << anotherTest.getSize() << '\n';
  81.  
  82.     Test myTest{ 555 }; //myTest.x myTest.ptr
  83.     myTest.setY(1);
  84.     newTest.setY(2);
  85.     anotherTest.setY(3);
  86.  
  87.     std::cout << myTest.getX() << '\n';
  88.     std::cout << myTest.getY() << '\n';
  89.     //std::cout << getXTest(&myTest) << '\n';
  90.     std::cout << newTest.getX() << '\n';
  91.     std::cout << newTest.getY() << '\n';
  92.     //std::cout << getXTest(&newTest) << '\n';
  93.     std::cout << anotherTest.getX() << '\n';
  94.     std::cout << anotherTest.getY() << '\n';
  95.     //std::cout << getXTest(&anotherTest) << '\n';
  96.     //myTest.sub(555).add(10).add(2).mul(2); // x == 24;
  97.     ////myTest.sub(555);  // x == 0;
  98.     //myTest.add(10); // x == 10;
  99.     ////myTest.add(2); // x == 12;
  100.     ////myTest.mul(2); // x == 24;
  101.     //std::cout << myTest.getX() << '\n'; //24
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement