14-ConstClasses - #include <iostream> using namespace...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
#include <iostream> using namespace std; class Point { private: float x, y; public: Point(float x1 = 0.0f, float y1 = 0.0f) // faciliatates as the default constructor { setCoordinates(x1, y1); publicInt = 55; } void setCoordinates(float x1, float y1) { x = x1; y = y1; } //void invalidConst(float x1) const //{ // x = x1; //} // const marks the function as not being allowed to alter members float getX() const { return x; } float getY() { return y; } void print() const { cout << "(" << x << ", " << y << ")" << endl; } ~Point() {} // Invalid destructor: /*~Point(int x) {}*/ int publicInt; }; // Constructors and destructors cannot be marked as const // but are still used by const objects // const members // the variable is still a class level variable, so the // lifetime of the v class Consts { private: const int x; public:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
// const members must be initialized in our constructors // these give errors: /* Consts() {} Consts(int init) {} Consts() { x = 0; // this does not work, must be done in initializer list
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/05/2011 for the course CS 37 taught by Professor Glenncuevas during the Summer '09 term at Irvine Valley College.

Page1 / 3

14-ConstClasses - #include &lt;iostream&gt; using namespace...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online