Return to the C++ Demos Home Page
SAMS Teach Yourself C++ in 21 Days
Chapter Seventeen
Prog 1 : Using Namespaces
// STYC++ in 21 days chapter 17 p 1
//
// Using namespaces
//
//
#include <iostream>
namespace Window
{
const int MAX_X = 30;
const int MAX_Y = 40;
class Pane
{
public:
Pane();
~Pane();
void size(int x, int y);
void move(int x, int y);
void show();
private:
static int cnt;
int x;
int y;
}; //end of class pane def
} // eon <-- end of namespace
int Window::Pane::cnt = 0;
Window::Pane::Pane() : x(0), y(0) {} // constructor
Window::Pane::~Pane() {} // destructor
void Window::Pane::size( int x, int y )
{
if ( x < Window::MAX_X && x > 0 ) Pane::x = x;
if ( y < Window::MAX_Y && y > 0 ) Pane::y = y;
}
void Window::Pane::move(int x,int y)
{
if ( x < Window::MAX_X && x > 0 ) Pane::x = x;
if ( y < Window::MAX_Y && y > 0 ) Pane::y = y;
}
void Window::Pane::show()
{
std::cout << " x : " << Pane::x;
std::cout << " and y : " << Pane::y << std::endl;
}
// driver
int main()
{
Window::Pane pane;
pane.move(20,20);
pane.show();
return 0;
} // eos