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 [2017/04/20 15:51] gthanoscpp:friend_methods [2017/04/20 15:58] – [Φιλικές Κλάσεις] gthanos
Line 84: Line 84:
  
 class Cuboid { class Cuboid {
-  Rectangle r;+  Rectangle rect;
   int length;   int length;
 public: public:
-  void modifyDimensions(int dw, int dh, int dl+  Cuboid(Rectangle r, int l); 
-    r.width += dw+  int volume();
-    r.height += dh; +
-    length += dl; +
-  }+
 } }
-<code>+ 
 +Cuboid::Cuboid(Rectangle r, int l) { 
 +  rect = r; length = l; 
 +
 + 
 +int Cuboid::volume() { 
 +  return r.width * r.height * length; 
 +
 +</code> 
 + 
 +<code cpp CuboidVolume.cpp> 
 +#include <iostream> 
 + 
 +int main() { 
 +  Rectangle rectangle(5,6); 
 +  Cuboid cuboid(r, 10); 
 +  cout << "volume: " << cuboid.volume() << endl; 
 +
 +</code>
cpp/friend_methods.txt · Last modified: 2021/05/18 06:21 (external edit)