Advertisement
Guest User

Untitled

a guest
Jan 11th, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.71 KB | None | 0 0
  1. C++:
  2.  
  3. #include <cassert>
  4. #include <string>
  5. #include <iostream>
  6.  
  7. using namespace std;
  8.  
  9. struct lim {
  10.     const double min = -10, max = 10;
  11.     double val;
  12.     lim(double v) {
  13.         assert(v >= min && v <= max);
  14.         val = v;
  15.     }
  16.     lim& operator=(double v) {
  17.         assert(v >= min && v <= max);
  18.         val = v;
  19.     }
  20.     operator double() const {
  21.         return val;
  22.     }
  23. };
  24.  
  25. struct point {
  26.     lim x,y;
  27.     point(double _x, double _y)
  28.         : x(_x), y(_y) { }
  29. };
  30. ostream& operator<<(ostream& s, const point& p) {
  31.     s << "[" << + p.x << "," << p.y << "]";
  32.     return s;
  33. }
  34.  
  35. int
  36. main() {
  37.     point p(5,3);
  38.     cout << p << endl;
  39.     p.y = 17.3;
  40.     cout << p << endl;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement