| <<< Encapsulation | Index | Creating your own classes >>> |
Recall class with a function:
// main.cpp
class Point {
public:
// member variables
int x;
int y;
// member functions
void adjust( int xx, int yy )
{
x += xx;
y += yy;
}
}; // don't forget this semicolon!
int main()
{
// Create object
Point pt;
// access to member variables
pt.x = 5;
pt.y = 4;
pt.adjust( 1, 1 ); // member function call
return 0;
}
| <<< Encapsulation | Index | Creating your own classes >>> |