cpp:vector_overloading

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
cpp:vector_overloading [2017/05/12 05:01]
gthanos
cpp:vector_overloading [2019/05/16 07:29]
gthanos
Line 9: Line 9:
 class Vector { class Vector {
   int *array;   int *array;
-  unsigned int size;+  int size;
      
 public: public:
-  Vector(unsigned int length=0);+  Vector(int length=0);
   Vector(const Vector &v);   Vector(const Vector &v);
   Vector(const Vector *v);   Vector(const Vector *v);
   ~Vector();   ~Vector();
-  unsigned int length() const;// return Vector's length. +  int length() const;// return Vector's length. 
-  int &valueAt(unsigned int pos) const;  // return a reference to element at position pos+  int &valueAt(int pos) const;  // return a reference to element at position pos
   int find(int a) const;      // check if a exists in Vector. Return it position >0 or -1    int find(int a) const;      // check if a exists in Vector. Return it position >0 or -1 
                               // if not element not found                               // if not element not found
Line 24: Line 24:
 }; };
  
-Vector::Vector(unsigned int length) {+Vector::Vector(int length) {
   size = length;   size = length;
   array = new (nothrow) int[size];   array = new (nothrow) int[size];
Line 61: Line 61:
 } }
  
-unsigned int Vector::length() const { +int Vector::length() const { 
   return size;    return size; 
 } }
  
-int &Vector::valueAt(unsigned int pos) const {+int &Vector::valueAt(int pos) const {
   if(pos>=length()) {   if(pos>=length()) {
      cerr << "Invalid access position!\n";      cerr << "Invalid access position!\n";
Line 99: Line 99:
  
 Για την παραπάνω κλάση κλάση //Vector// θέλουμε να υπερφορτώσουμε τους τελεστές ανά κατηγορία ως εξής: Για την παραπάνω κλάση κλάση //Vector// θέλουμε να υπερφορτώσουμε τους τελεστές ανά κατηγορία ως εξής:
-  * [[cpp:vector_overloading_unary_operators|Υπερφόρτωση μοναδιαίων τελεστών]]+  * [[cpp:vector_overloading_unary_operators| Υπερφόρτωση μοναδιαίων τελεστών ]] 
 +  * [[cpp:vector_overloading_binary_operators| Υπερφόρτωση δυαδικών τελεστών που μπορούν να υλοποιηθούν ως μέλη της κλάσης ή ως φιλικές συναρτήσεις ]] 
 +  * [[cpp:vector_overloading_binary_operators2| Υπερφόρτωση δυαδικών τελεστών μπορούν να υλοποιηθούν μόνο ως μέλη της κλάσης ]]
  
  
cpp/vector_overloading.txt · Last modified: 2021/05/24 06:35 (external edit)