Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Point {
- private:
- mutable int x;// we can change the value inside constant functions
- int y;
- public:
- Point(int _x = 0, int _y = 0) {
- x = _x;
- y = _y;
- }
- Point(const Point &tmp) {
- x = tmp.x;
- y = tmp.y;
- }
- int get_x() const { // this means we cannot change any variable in the function
- x++; // since it's mutable, the value can be chagned even though it is a constant function
- return x;
- }
- int get_y() const {
- return y;
- }
- };
- int main()
- {
- Point p(10, 20);
- cout << p.get_x() << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement