Advertisement
paulll

example.cpp

Dec 10th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.65 KB | None | 0 0
  1. #include <algorithm>
  2. #include <iostream>
  3. #include <memory>
  4. #include <list>
  5.  
  6. class Name
  7. {
  8.   public:
  9.     Name()
  10.     {
  11.       std::cout << "Name" << std::endl;
  12.     }
  13.     virtual ~Name() {};
  14.     Name operator+(int rhs)
  15.     {
  16.       val += rhs;
  17.       return *this;
  18.     }
  19.     Name& operator=(int rhs)
  20.     {
  21.       val = rhs;
  22.       return *this;
  23.     }
  24.  
  25.     friend std::ostream& operator<<(std::ostream& os, const Name& c)
  26.     {
  27.       os << c.val;
  28.       return os;
  29.     }
  30.  
  31.   private:
  32.     int val { 0 };
  33. };
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37.   Name n;
  38.   (n + 1) = 40;
  39.   std::cout << n << std::endl;
  40.  
  41.   const char* n2 = "maciejek";
  42.   std::cout << std::string(n2, 2) << std::endl;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement