User Tools

Site Tools


cpp:friend_methods

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
Next revisionBoth sides next revision
cpp:friend_methods [2019/04/19 10:04] – [Φιλικές Συναρτήσεις] gthanoscpp:friend_methods [2019/04/19 10:08] – [Φιλικές Κλάσεις] gthanos
Line 16: Line 16:
     int getWidth();     int getWidth();
     int getHeight();     int getHeight();
-    friend void modifyDimensions(Rectangle r, int dw, int dh);+    friend void modifyDimensions(Rectangler, int dw, int dh);
 }; };
  
Line 28: Line 28:
 int Rectangle::getHeight() { return height; } int Rectangle::getHeight() { return height; }
  
-void modifyDimensions(Rectangle r, int dw, int dh) {+void modifyDimensions(Rectangler, int dw, int dh) {
   r.width += dw;   r.width += dw;
   r.height += dh;   r.height += dh;
Line 35: Line 35:
  
 <code cpp RectangleUsage.hpp> <code cpp RectangleUsage.hpp>
-#include "Rectangle.cpp"+#include "Rectangle.hpp"
  
 int main () { int main () {
Line 50: Line 50:
 Σε αναλογία με τις φιλικές συναρτήσεις μπορείτε να έχετε και φιλικές κλάσεις που έχουν πρόσβαση στο σύνολο των πεδίων κλάσης. Στο παρακάτω παράδειγμα, η κλάση //Cuboid// είναι φιλική της κλάσης //Rectangle//. Ως φιλική κλάση έχει πρόσβαση στο σύνολο των πεδίων και των μεθόδων της κλάσης //Rectangle// Σε αναλογία με τις φιλικές συναρτήσεις μπορείτε να έχετε και φιλικές κλάσεις που έχουν πρόσβαση στο σύνολο των πεδίων κλάσης. Στο παρακάτω παράδειγμα, η κλάση //Cuboid// είναι φιλική της κλάσης //Rectangle//. Ως φιλική κλάση έχει πρόσβαση στο σύνολο των πεδίων και των μεθόδων της κλάσης //Rectangle//
  
-<code cpp Rectangle.cpp>+<code cpp Rectangle.hpp>
 #include <iostream> #include <iostream>
 using namespace std; using namespace std;
Line 77: Line 77:
 </code> </code>
  
-<code cpp Cuboid.cpp>+<code cpp Cuboid.hpp>
 #include <iostream> #include <iostream>
 using namespace std; using namespace std;
  
-#include "Rectangle.cpp"+#include "Rectangle.hpp"
  
 class Cuboid { class Cuboid {
Line 104: Line 104:
 using namespace std; using namespace std;
  
-#include "Cuboid.cpp"+#include "Cuboid.hpp"
  
 int main() { int main() {
cpp/friend_methods.txt · Last modified: 2021/05/18 06:21 (external edit)