Guest User

Untitled

a guest
Dec 16th, 2015
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. class Vector {
  2. private:
  3. double *vec;
  4. public:
  5. Vector() : vec(NULL) {}
  6. Vector(double a, double b)
  7. {
  8. vec = new double[2];
  9. vec[0] = a;
  10. vec[1] = b;
  11. }
  12. ~Vector() {
  13. if (vec) {
  14. delete[] vec;
  15. vec = NULL;
  16. }
  17. }
  18. void disp() {
  19. if (vec) cout << vec[0] << " " << vec[1] << endl;
  20. else cout << "NULL" << endl;
  21. }
  22. Vector & operator=(Vector &p) {
  23. if (p.vec) {
  24. if (this->vec) {
  25. vec[0] = p.vec[0];
  26. vec[1] = p.vec[1];
  27. return *this;
  28. }
  29. else {
  30. this->vec = new double[2];
  31. vec[0] = p.vec[0];
  32. vec[1] = p.vec[1];
  33. return *this;
  34. }
  35. }
  36. else {
  37. if (this->vec) {
  38. delete[] this->vec;
  39. this->vec = NULL;
  40. return *this;
  41. }
  42. } return *this;
  43. }
  44.  
  45. Vector operator*(Vector &(&p)) {
  46. return *this;
  47. }
  48.  
  49. };
  50.  
  51. int main()
  52. {
  53. Vector a(1, 2), b(2, 3), c;
  54. a.disp();
  55. b.disp();
  56. c.disp();
  57. c = a;
  58. c.disp();
  59.  
  60. c=a*(&b);
  61. c.disp();
  62.  
  63. system("PAUSE");
  64. return 0;
  65. }
Advertisement
Add Comment
Please, Sign In to add comment