10-ThisAndAccessModifiers

10-ThisAndAccessModi - the data aspect of the class seperate from the functional aspect which means that all of your public and private variables

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

View Full Document Right Arrow Icon
#include <iostream> using namespace std; class Point { int x; int y; public: Point() { x = y = 0; } Point(int x, int y) { this->x = x; this->y = y; (*this).x = x; // The this keyword is a pointer to the // current object } void print() { cout << "(" << x << ", " << y << ")" << endl; } void Address() { cout << "Current object location: " << this << endl; } }; class LotsOPrivate { private: int data; private: int moreData; public: LotsOPrivate(int a, int b) { data = a; moreData = b; } private: LotsOPrivate() {} // ensuring that an empty object cannot be built public: int publicData; }; // notice that public and private can be used more than // once, an access section goes from one label to the next // in practice this can be used well if you want to keep
Background image of page 1

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

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // the data aspect of the class seperate from the functional // aspect, which means that all of your public and private // variables could be declared in one part, then all of // the constructors in another, then the functions, which // you could group based upon other logic int main(void) { Point p1(4,5); p1.print(); //cout << p1.x << endl; // Note, that even though x & y do not appear // to be in a private section, they are still // private, as private access is the default p1.Address(); cout << "p1 can be found at " << &p1 << endl; return 0; } /* (4, 5) Current object location: 0012FF5C p1 can be found at 0012FF5C Press any key to continue . . . */...
View Full 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 / 2

10-ThisAndAccessModi - the data aspect of the class seperate from the functional aspect which means that all of your public and private variables

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

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