Advertisement
bogolyubskiyalexey

Untitled

Feb 24th, 2021
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. class Complex {
  4.     double Re_;
  5.     double Im_;
  6.    
  7.     public:
  8.         Complex(const double re, const double im = 0) : Re_(re), Im_(im) {}
  9.        
  10.         /*Complex operator+ (const Complex& other) const {
  11.             return Complex(Re_ + other.Re_, Im_ + other.Im_);
  12.         }*/
  13.        
  14.         const double& Re() const {
  15.             return Re_;
  16.         }
  17.  
  18.         double& Re() {
  19.             return Re_;
  20.         }
  21.  
  22.         double Im() const {
  23.             return Im_;
  24.         }
  25.        
  26.         friend Complex operator+ (const Complex& a, const Complex& b);
  27.         friend void show(const Complex& a);
  28.  
  29.         Complex& operator++() {
  30.             ++Re_;
  31.             return *this;
  32.         }
  33.  
  34.         Complex operator++ (int) {
  35.             Complex temp = *this;
  36.             ++Re_;
  37.             return temp;
  38.         }
  39.  
  40. };
  41.  
  42.  
  43.  
  44.  
  45. void show(const Complex& a) {
  46.     std::cout << a.Im_ << " " << a.Re_ << std::endl;
  47. }
  48.  
  49. Complex operator- (const Complex& a, const Complex& b) {
  50.     return Complex(a.Re() - b.Re(), a.Im() - b.Im());
  51. }
  52.  
  53.  
  54. Complex operator+ (const Complex& a, const Complex& b) {
  55.     return Complex(a.Re_ + b.Re_, a.Im_ + b.Im_);
  56. }
  57.  
  58. Complex operator+ (const Complex& a, int b) {
  59.     return Complex(a.Re() + b, a.Im());
  60. }
  61. Complex operator+ (int a, const Complex& b) {
  62.     return b + a;
  63. }
  64.  
  65.  
  66. struct Type {
  67.     int& ref;
  68.  
  69.     Type(int& other) : ref(other) {}
  70. };
  71.  
  72. struct Object {
  73.  
  74. }
  75.  
  76. int main() {
  77.     Complex a(10, 10);
  78.     Complex c = a + 5; // + Complex(double(5));
  79.     Complex d = 5 + a; // CE
  80.     Complex e = 5 - a; // OK Complex(double(5)) - a
  81.  
  82.  
  83.     ++a;
  84.  
  85.     int value = 10;
  86.     int q = ++value;
  87.     int w = value++;
  88.     //a++;
  89.  
  90.     for (Complex a(0); a.Re() < 10; a++) {
  91.  
  92.     }
  93.  
  94.     std::vector<Type> v;
  95.     {
  96.         int value = 10;
  97.         int& a = value;
  98.         v.push_back(Type(a));
  99.     }
  100.     v.front().ref = 10;
  101.  
  102.     Number a;
  103.     (++a) = Number(10);
  104.  
  105.     a += 10;
  106.    
  107. }
  108.  
  109. /*
  110.  
  111. a = [1,2,3]
  112. b = a
  113.  
  114. b[2] = 3
  115. a[2] = 5
  116. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement