This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
cpp:const_member_functions [2017/05/15 06:42] gthanos created |
cpp:const_member_functions [2021/05/07 07:50] |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== Const μέθοδοι της κλάσης ====== | ||
| - | |||
| - | Όταν δηλώνεται ένα αντικείμενο ως //const// (όπως παρακάτω), | ||
| - | |||
| - | <code cpp Rectangle.cpp> | ||
| - | #include < | ||
| - | using namespace std; | ||
| - | |||
| - | class Rectangle { | ||
| - | private: | ||
| - | int width, height; | ||
| - | public: | ||
| - | Rectangle(int width, int height); | ||
| - | void setWidth(int width); | ||
| - | void setHeight(int height); | ||
| - | int getWidth(); | ||
| - | int getHeight(); | ||
| - | }; | ||
| - | |||
| - | Rectangle:: | ||
| - | this-> | ||
| - | } | ||
| - | |||
| - | void Rectangle:: | ||
| - | void Rectangle:: | ||
| - | int Rectangle:: | ||
| - | int Rectangle:: | ||
| - | |||
| - | int main() { | ||
| - | const Rectangle rect(10, | ||
| - | } | ||
| - | </ | ||
| - | |||
| - | |||
| - | |||