cpp:friend_methods
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
cpp:friend_methods [2017/04/20 16:11] – [Φιλικές Κλάσεις] gthanos | cpp:friend_methods [2019/04/19 10:07] – [Φιλικές Συναρτήσεις] gthanos | ||
---|---|---|---|
Line 3: | Line 3: | ||
Μία φιλική συνάρτηση της κλάσης είναι μία συνάρτηση που δεν είναι μέλος της κλάσης, | Μία φιλική συνάρτηση της κλάσης είναι μία συνάρτηση που δεν είναι μέλος της κλάσης, | ||
- | <code cpp Rectangle.cpp> | + | <code cpp Rectangle.hpp> |
#include < | #include < | ||
using namespace std; | using namespace std; | ||
Line 16: | Line 16: | ||
int getWidth(); | int getWidth(); | ||
int getHeight(); | int getHeight(); | ||
- | friend void modifyDimensions(Rectangle r, int dw, int dh); | + | friend void modifyDimensions(Rectangle& r, int dw, int dh); |
}; | }; | ||
Line 28: | Line 28: | ||
int Rectangle:: | int Rectangle:: | ||
- | void modifyDimensions(Rectangle r, int dw, int dh) { | + | void modifyDimensions(Rectangle& r, int dw, int dh) { |
r.width += dw; | r.width += dw; | ||
r.height += dh; | r.height += dh; | ||
Line 34: | Line 34: | ||
</ | </ | ||
- | <code cpp RectangleUsage.cpp> | + | <code cpp RectangleUsage.hpp> |
- | #include " | + | #include " |
int main () { | int main () { | ||
Line 113: | Line 113: | ||
</ | </ | ||
- | <WRAP center round tip 60%> | + | <WRAP center round tip 80%> |
Παρατηρήστε πως η μέθοδος //volume// της κλάσης //Cuboid// υπολογίζει τον όγκο έχοντας απευθείας πρόσβαση στα πεδία της κλάσης // | Παρατηρήστε πως η μέθοδος //volume// της κλάσης //Cuboid// υπολογίζει τον όγκο έχοντας απευθείας πρόσβαση στα πεδία της κλάσης // | ||
</ | </ |
cpp/friend_methods.txt · Last modified: 2021/05/18 06:21 (external edit)