cpp:object_creation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
cpp:object_creation [2017/05/10 05:51] – [Παράδειγμα αρχικοποίησης δεικτών] gthanos | cpp:object_creation [2018/05/02 08:35] – [Παράδειγμα αρχικοποίησης δεικτών] gthanos | ||
---|---|---|---|
Line 159: | Line 159: | ||
<code cpp Rectangle.cpp> | <code cpp Rectangle.cpp> | ||
#include < | #include < | ||
+ | #include < | ||
using namespace std; | using namespace std; | ||
class Rectangle { | class Rectangle { | ||
private: | private: | ||
- | int width, height; | + | int *width, |
public: | public: | ||
Rectangle(int w, int h); | Rectangle(int w, int h); | ||
- | Rectangle(int s); | + | |
- | Rectangle(); | + | |
- | int getWidth() const; | + | |
- | int getHeight() const; | + | |
void setWidth(int w); | void setWidth(int w); | ||
void setHeight(int h); | void setHeight(int h); | ||
- | int getArea() | + | |
+ | int getHeight(); | ||
+ | | ||
}; | }; | ||
- | Rectangle:: | + | Rectangle:: |
- | Rectangle:: | + | |
- | Rectangle:: | + | |
+ | if(width | ||
+ | cerr << " | ||
+ | exit(-1); | ||
+ | | ||
+ | | ||
+ | cout << " | ||
+ | } | ||
- | int Rectangle::getWidth() const { return width;} | + | Rectangle::~Rectangle() { |
- | int Rectangle::getHeight() const { return | + | cout << " |
- | void Rectangle:: | + | delete width; |
- | void Rectangle:: | + | delete |
- | int Rectangle:: | + | } |
+ | |||
+ | void Rectangle:: | ||
+ | void Rectangle:: | ||
+ | int Rectangle:: | ||
+ | int Rectangle:: | ||
+ | int Rectangle:: | ||
</ | </ | ||
cpp/object_creation.txt · Last modified: 2021/05/07 06:22 (external edit)