cpp:vector_overloading
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| cpp:vector_overloading [2019/05/16 07:29] – gthanos | cpp: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 < | #include < | ||
| #include < | #include < | ||
| using namespace std; | using namespace std; | ||
| + | |||
| + | #ifndef _VECTOR_HPP_ | ||
| + | #define _VECTOR_HPP_ | ||
| class Vector { | class Vector { | ||
| Line 24: | Line 27: | ||
| }; | }; | ||
| + | #endif | ||
| + | </ | ||
| + | |||
| + | <code cpp Vector.cpp> | ||
| + | #include " | ||
| Vector:: | Vector:: | ||
| size = length; | size = length; | ||
| Line 89: | Line 97: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | <code cpp VectorUsage.cpp> | ||
| + | #include " | ||
| 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(); | ||
| } | } | ||
| </ | </ | ||
cpp/vector_overloading.1557991793.txt.gz · Last modified: 2019/05/16 06:29 (external edit)
