User Tools

Site Tools


cpp:vector_overloading

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
cpp:vector_overloading [2019/05/16 07:29] gthanoscpp:vector_overloading [Unknown date] (current) – external edit (Unknown date) 127.0.0.1
Line 2: Line 2:
  
 Ας υποθέσουμε ότι έχουμε την παρακάτω κλάση //Vector// η οποία υλοποιεί ένα μονοδιάστατο πίνακα από ακεραίους. Ας υποθέσουμε ότι έχουμε την παρακάτω κλάση //Vector// η οποία υλοποιεί ένα μονοδιάστατο πίνακα από ακεραίους.
-<code cpp Vector.cpp>+<code cpp Vector.hpp>
 #include <iostream> #include <iostream>
 #include <cstdlib> #include <cstdlib>
 using namespace std; using namespace std;
 +
 +#ifndef _VECTOR_HPP_
 +#define _VECTOR_HPP_
  
 class Vector { class Vector {
Line 24: Line 27:
 }; };
  
 +#endif
 +</code>
 +
 +<code cpp Vector.cpp>
 +#include "Vector.hpp"
 Vector::Vector(int length) { Vector::Vector(int length) {
   size = length;   size = length;
Line 89: Line 97:
   }   }
 } }
 +</code>
  
 +<code cpp VectorUsage.cpp>
 +#include "Vector.hpp"
 int main() { int main() {
   Vector v(5);   Vector v(5);
   v.valueAt(0) = 2;  v.valueAt(1) = 3;   v.valueAt(0) = 2;  v.valueAt(1) = 3;
-  v.valueAt(2) = 4;  v.valueAt(3) = 5;  v.valueAt(4) = 6; +  v.valueAt(2) = 4;  v.valueAt(3) = 5;  v.valueAt(4) = 6
 +  cout << "value 5 at position: " << v.find(5) << endl; 
 +  cout << "value 10 at position: " << v.find(10) << endl; 
 +  v.print();
 } }
 </code> </code>
cpp/vector_overloading.1557991793.txt.gz · Last modified: 2019/05/16 06:29 (external edit)