x 20 y 20
Note that class Paneon lines 7–19 is nested inside the namespace Window, which
is on lines 3–20. This is the reason you have to qualify the name Panewith the
Window::qualifier.
The static variable count, which is declared in Paneon line 16, is defined as usual.
Within the function Pane::size()on lines 26–32, notice that MAX_Xand MAX_Yare fully
qualified. This is because Paneis in scope; otherwise, the compiler issues an error diag-
nostic. This also holds true for the function Pane::move().
Also interesting is the qualification of Pane::xand Pane::yinside both function defini-
tions. Why is this needed? Well, if the function Pane::move()were written like this, you
would have a problem:
void Window::Pane::move( int x, int y )
{
if( x < Window::MAX_X && x > 0 )
x = x ;
if( y < Window::MAX_Y && y > 0 )
y = y ;
Platform::move( x, y ) ;
}
Can you spot the issue? You probably won’t get much of an answer from your compiler;
some don’t issue any kind of diagnostic message at all.
The source of the problem is the function’s arguments. Arguments xand yhide the pri-
vate xand yinstance variables declared within class Pane. Effectively, the statements
assign both xand yto itself:
x = x ;
y = y ;
The usingKeyword ............................................................................................
Theusingkeyword is used for both the usingdirective and the usingdeclaration.
The syntax of the usingkeyword determines whether the context is a directive or a
declaration.
The usingDirective........................................................................................
Theusingdirective effectively exposes all names declared in a namespace to be in the
current scope. You can refer to the names without qualifying them with their respective
namespace name. The following example shows the usingdirective:
648 Day 18
OUTPUT
ANALYSIS