Advertisement
Vermiculus

Operator Overloads

Feb 20th, 2012
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. /*
  2.  *  DynArray.h
  3.  */
  4.  
  5. #include <cstdlib>
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. class DynArray;
  11. ostream& operator << (ostream&, DynArray&);
  12. istream& operator >> (istream&, LDynArray&);
  13.  
  14. //...
  15.  
  16. class DynArray {
  17.    
  18.     friend ostream& operator << (ostream&, DynArray&);
  19.     friend istream& operator >> (istream&, DynArray&);
  20.    
  21. public:
  22.     /*
  23.        Shorthand append
  24.      */
  25.     void operator += (T);
  26.    
  27.     /*
  28.      Successfully sets a value
  29.      from the list (shorthand set(int, T))
  30.      */
  31.     int& operator [](const int);
  32.    
  33.     /*
  34.      Successfully gets a value
  35.      from the list (shorthand get(int))
  36.      */
  37.     int operator [](const int) const;
  38.    
  39.     /*
  40.        Reference assignment
  41.      */
  42.     void operator =(LinkedList&);
  43. //...
  44. };
  45.  
  46. /*
  47.  *  DynArray.cpp
  48.  */
  49.  
  50. //// ... stuff ...
  51.  
  52. /**********************/
  53. /* Operator Overloads */
  54. /**********************/
  55.  
  56.  
  57. void DynArray::operator = (DynArray& l) {
  58.     // implementation
  59. }
  60.  
  61. void DynArray::operator += (T val) {
  62.     // implementation
  63. }
  64.  
  65. int& // set
  66. DynArray::operator [] (const int i) {
  67.     return this->get(i)->value;
  68. }
  69.  
  70. int // get
  71. DynArray::operator [] (const int i) const {
  72.     return this->get(i)->value;
  73. }
  74.  
  75. /***** Insertion and Extraction *****/
  76.  
  77. ostream& operator << (ostream &os, DynArray &list) {
  78.     // implementation
  79. }
  80.  
  81. istream& operator >> (istream &is, DynArray &list) {
  82.     //implementation
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement