User Tools

Site Tools


cpp:object_creation

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:object_creation [2017/05/09 13:35] – [Δημιουργία αντικειμένων] gthanoscpp:object_creation [2017/05/10 04:49] – [Δημιουργία αντικειμένων] gthanos
Line 10: Line 10:
     int width, height;     int width, height;
   public:   public:
 +    Rectangle(int w, int h);
 +    Rectangle(int s);
 +    Rectangle();
     int getWidth() const;     int getWidth() const;
     int getHeight() const;     int getHeight() const;
Line 16: Line 19:
 }; };
  
-Rectangle::Rectangle(int w, int h) +Rectangle::Rectangle(int w, int h)width(w), height(h) {
-  width wheight h+Rectangle::Rectangle(int s) width(s), height(s) {} 
-} +Rectangle::Rectangle(): width(0), height(0) {}
- +
-Rectangle::Rectangle(int s) +
-  width height s; +
-}+
  
 int Rectangle::getWidth() const { return width;} int Rectangle::getWidth() const { return width;}
Line 36: Line 35:
 </code> </code>
  
-Ο παραπάνω κώδικας δημιουργεί 3 αντικείμενα της κλάσης //Rectangle// το αντικείμενο //rect1// με πλευρές 3 και 4, το //rect2// με πλευρές κοινού μήκους 5 και το αντικείμενο //rect3// που λαμβάνει τυχαίες τιμές. +Ο παραπάνω κώδικας δημιουργεί 3 αντικείμενα της κλάσης //Rectangle// το αντικείμενο //rect1// με πλευρές 3 και 4, το //rect2// με πλευρές κοινού μήκους 5 και το αντικείμενο //rect3// που έχει μηδενικές τιμές. 
  
 <WRAP center round tip 80%> <WRAP center round tip 80%>
cpp/object_creation.txt · Last modified: 2021/05/07 06:22 (external edit)