/* Testing constant data members (TestConstantData.cpp) */ #include using namespace std; class Point { private: int x; const int y; // constant data member, cannot be modified by member functions public: Point(int x = 0, int y = 0) : x(x), y(y) { } // init const data member via member initializer list int getX() const { return x; } int getY() const { return y; } void setX(int x) { this->x = x; } // modify non-const data member x // void setY(int y) { this->y = y; } // error: assignment of read-only member void print() const { cout << "(" << x << "," << y << ")" << endl; } // const };