Advertisement
Marf_72

Untitled

Mar 31st, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <iostream>
  2. #include "IntCounter.h"
  3.  
  4. using namespace std;
  5.  
  6.  
  7. IntCounter::IntCounter(){}
  8.  
  9. IntCounter::IntCounter(int* _num){
  10. this->setNum(_num);
  11. this->setCount(new int(1));
  12. }
  13.  
  14. IntCounter::IntCounter(const IntCounter& other){
  15. this->setNum(other.getNum());
  16. this->setCount(other.getCount());
  17. *this->getCount() = *this->getCount() + 1;
  18. }
  19.  
  20. IntCounter& IntCounter::operator=(const IntCounter& other){
  21. if(this == &other){
  22. return *this;
  23. }
  24.  
  25. this->setNum(other.getNum());
  26. this->setCount(other.getCount());
  27. *this->getCount() = *this->getCount() + 1;
  28.  
  29. return *this;
  30. }
  31.  
  32. IntCounter::~IntCounter(){
  33.  
  34. *this->getCount() = *this->getCount() - 1;
  35. if(this->getCount() == 0){
  36. delete[] this->num;
  37. delete[] this->count;
  38. }
  39. }
  40.  
  41. void IntCounter::setNum(int* _num){
  42. this->num = _num;
  43. }
  44.  
  45. int* IntCounter::getNum() const{
  46. return this->num;
  47. }
  48.  
  49. void IntCounter::setCount(int* _count){
  50. this->count = _count;
  51. }
  52.  
  53. int* IntCounter::getCount() const{
  54. return this->count;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement