SabirSazzad

Copy constructor

Feb 23rd, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class DZS
  5. {
  6. private:
  7.     int *student;
  8. public:
  9.     int getAmount();
  10.     DZS(int amount);
  11.     DZS(const DZS &lol);
  12.     ~DZS();
  13. };
  14.  
  15. DZS::DZS(int amount)
  16. {
  17.     cout << "Constructor Called"<<endl;
  18.     student = new int;
  19.     *student = amount;
  20. }
  21. DZS::DZS(const DZS &lol)
  22. {
  23.     cout << " COPY Constructor Called"<<endl;
  24.     student = new int;
  25.     *student = *lol.student;
  26. }
  27. DZS::~DZS()
  28. {
  29.     cout << "Destreactor Called."<<endl;
  30.     delete student;
  31. }
  32. int DZS::getAmount()
  33. {
  34.     return *student;
  35. }
  36. void display(DZS lol)
  37. {
  38.     cout << "Total Student in DZS is: " << lol.getAmount() <<endl;
  39. }
  40. int main()
  41. {
  42.     DZS dzs(2000);
  43.     display(dzs);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment