<s>
A	O
class	O
in	O
C++	O
is	O
a	O
user-defined	B-Language
type	I-Language
or	O
data	B-General_Concept
structure	I-General_Concept
declared	O
with	O
keyword	O
class	O
that	O
has	O
data	O
and	O
functions	O
(	O
also	O
called	O
member	B-Application
variables	I-Application
and	O
member	O
functions	O
)	O
as	O
its	O
members	O
whose	O
access	O
is	O
governed	O
by	O
the	O
three	O
access	O
specifiers	O
private	O
,	O
protected	O
or	O
public	O
.	O
</s>
<s>
By	O
default	B-General_Concept
access	O
to	O
members	O
of	O
a	O
C++	B-Application
class	I-Application
is	O
private	O
.	O
</s>
<s>
The	O
public	O
members	O
form	O
an	O
interface	B-Application
to	O
the	O
class	O
and	O
are	O
accessible	O
outside	O
the	O
class	O
.	O
</s>
<s>
Instances	O
of	O
a	O
class	O
data	O
type	O
are	O
known	O
as	O
objects	O
and	O
can	O
contain	O
member	B-Application
variables	I-Application
,	O
constants	O
,	O
member	O
functions	O
,	O
and	O
overloaded	O
operators	O
defined	O
by	O
the	O
programmer	O
.	O
</s>
<s>
In	O
C++	O
,	O
a	O
class	O
defined	O
with	O
the	O
class	O
keyword	O
has	O
private	O
members	O
and	O
base	O
classes	O
by	O
default	B-General_Concept
.	O
</s>
<s>
A	O
structure	O
is	O
a	O
class	O
defined	O
with	O
the	O
struct	B-Application
keyword	O
.	O
</s>
<s>
Its	O
members	O
and	O
base	O
classes	O
are	O
public	O
by	O
default	B-General_Concept
.	O
</s>
<s>
In	O
practice	O
,	O
structs	B-Application
are	O
typically	O
reserved	O
for	O
data	O
without	O
functions	O
.	O
</s>
<s>
When	O
deriving	O
a	O
struct	B-Application
from	O
a	O
class/struct	O
,	O
default	B-General_Concept
access-specifier	O
for	O
a	O
base	O
class/struct	O
is	O
public	O
.	O
</s>
<s>
And	O
when	O
deriving	O
a	O
class	O
,	O
default	B-General_Concept
access	O
specifier	O
is	O
private	O
.	O
</s>
<s>
A	O
POD-struct	B-Language
(	O
Plain	B-Language
Old	I-Language
Data	I-Language
Structure	I-Language
)	O
is	O
an	O
aggregate	O
class	O
that	O
has	O
no	O
non-static	O
data	O
members	O
of	O
type	O
non-POD-struct	O
,	O
non-POD-union	O
(	O
or	O
array	O
of	O
such	O
types	O
)	O
or	O
reference	O
,	O
and	O
has	O
no	O
user-defined	O
assignment	O
operator	O
and	O
no	O
user-defined	O
destructor	B-Language
.	O
</s>
<s>
A	O
POD-struct	B-Language
could	O
be	O
said	O
to	O
be	O
the	O
C++	O
equivalent	O
of	O
a	O
C	O
struct	B-Application
.	O
</s>
<s>
In	O
most	O
cases	O
,	O
a	O
POD-struct	B-Language
will	O
have	O
the	O
same	O
memory	O
layout	O
as	O
a	O
corresponding	O
struct	B-Application
declared	O
in	O
C	O
.	O
For	O
this	O
reason	O
,	O
POD-structs	O
are	O
sometimes	O
colloquially	O
referred	O
to	O
as	O
"	O
C-style	O
structs	B-Application
"	O
.	O
</s>
<s>
Two	O
POD-struct	B-Language
types	O
are	O
layout-compatible	O
if	O
they	O
have	O
the	O
same	O
number	O
of	O
nonstatic	O
data	O
members	O
,	O
and	O
corresponding	O
nonstatic	O
data	O
members	O
(	O
in	O
order	O
)	O
have	O
layout-compatible	O
types	O
.	O
</s>
<s>
A	O
POD-struct	B-Language
may	O
contain	O
unnamed	O
padding	B-Application
.	O
</s>
<s>
A	O
pointer	O
to	O
a	O
POD-struct	B-Language
object	O
,	O
suitably	O
converted	O
using	O
a	O
reinterpret	B-Language
cast	I-Language
,	O
points	O
to	O
its	O
initial	O
member	O
and	O
vice	O
versa	O
,	O
implying	O
that	O
there	O
is	O
no	O
padding	B-Application
at	O
the	O
beginning	O
of	O
a	O
POD-struct	B-Language
.	O
</s>
<s>
A	O
POD-struct	B-Language
may	O
be	O
used	O
with	O
the	O
offsetof	B-Language
macro	O
.	O
</s>
<s>
C++	B-Application
classes	I-Application
have	O
their	O
own	O
members	O
.	O
</s>
<s>
These	O
members	O
include	O
variables	O
(	O
including	O
other	O
structures	O
and	O
classes	O
)	O
,	O
functions	O
(	O
specific	O
identifiers	O
or	O
overloaded	O
operators	O
)	O
known	O
as	O
methods	O
,	O
constructors	O
and	O
destructors	B-Language
.	O
</s>
<s>
There	O
is	O
also	O
inheritance	B-Language
between	O
classes	O
which	O
can	O
make	O
use	O
of	O
the	O
protected	O
:	O
specifier	O
.	O
</s>
<s>
Classes	O
are	O
declared	O
with	O
the	O
class	O
or	O
struct	B-Application
keyword	O
.	O
</s>
<s>
An	O
important	O
feature	O
of	O
the	O
C++	B-Application
class	I-Application
and	O
structure	O
are	O
member	O
functions	O
.	O
</s>
<s>
Both	O
name_	O
and	O
age_	O
are	O
private	O
(	O
default	B-General_Concept
for	O
class	O
)	O
and	O
Print	O
is	O
declared	O
as	O
public	O
which	O
is	O
necessary	O
if	O
it	O
is	O
to	O
be	O
used	O
from	O
outside	O
the	O
class	O
.	O
</s>
<s>
where	O
a	O
and	O
b	O
above	O
are	O
called	O
senders	O
,	O
and	O
each	O
of	O
them	O
will	O
refer	O
to	O
their	O
own	O
member	B-Application
variables	I-Application
when	O
the	O
Print( )	O
function	O
is	O
executed	O
.	O
</s>
<s>
It	O
is	O
common	O
practice	O
to	O
separate	O
the	O
class	O
or	O
structure	O
declaration	O
(	O
called	O
its	O
interface	B-Application
)	O
and	O
the	O
definition	O
(	O
called	O
its	O
implementation	O
)	O
into	O
separate	O
units	O
.	O
</s>
<s>
The	O
interface	B-Application
,	O
needed	O
by	O
the	O
user	O
,	O
is	O
kept	O
in	O
a	O
header	B-Language
and	O
the	O
implementation	O
is	O
kept	O
separately	O
in	O
either	O
source	B-Application
or	O
compiled	B-Language
form	O
.	O
</s>
<s>
For	O
example	O
,	O
many	O
popular	O
C++	O
compilers	B-Language
implement	O
single	O
inheritance	B-Language
by	O
concatenation	O
of	O
the	O
parent	O
class	O
fields	O
with	O
the	O
child	O
class	O
fields	O
,	O
but	O
this	O
is	O
not	O
required	O
by	O
the	O
standard	O
.	O
</s>
<s>
Multiple	O
inheritance	B-Language
is	O
not	O
as	O
simple	O
.	O
</s>
<s>
Whenever	O
the	O
compiler	B-Language
needs	O
to	O
convert	O
a	O
pointer	O
from	O
the	O
D	O
type	O
to	O
either	O
P	O
or	O
C	O
,	O
the	O
compiler	B-Language
will	O
provide	O
an	O
automatic	O
conversion	O
from	O
the	O
address	O
of	O
the	O
derived	O
class	O
to	O
the	O
address	O
of	O
the	O
base	O
class	O
fields	O
(	O
typically	O
,	O
this	O
is	O
a	O
simple	O
offset	O
calculation	O
)	O
.	O
</s>
<s>
For	O
more	O
on	O
multiple	O
inheritance	B-Language
,	O
see	O
virtual	B-Application
inheritance	I-Application
.	O
</s>
<s>
For	O
clearer	O
presentation	O
(	O
although	O
this	O
could	O
decrease	O
efficiency	O
of	O
the	O
program	O
if	O
the	O
compiler	B-Language
cannot	O
optimize	O
the	O
statement	O
into	O
the	O
equivalent	O
one	O
above	O
)	O
,	O
the	O
above	O
code	O
can	O
be	O
rewritten	O
as	O
:	O
</s>
<s>
Programmers	O
can	O
also	O
put	O
a	O
prototype	O
of	O
the	O
operator	O
in	O
the	O
struct	B-Application
declaration	O
and	O
define	O
the	O
function	O
of	O
the	O
operator	O
in	O
the	O
global	O
scope	O
:	O
</s>
<s>
i	O
above	O
represents	O
the	O
sender	O
's	O
own	O
member	B-Application
variable	I-Application
,	O
while	O
k.i	O
represents	O
the	O
member	B-Application
variable	I-Application
from	O
the	O
argument	O
variable	O
k	O
.	O
</s>
<s>
The	O
second	O
incidence	O
at	O
the	O
end	O
of	O
the	O
declaration	O
promises	O
the	O
compiler	B-Language
that	O
the	O
sender	O
would	O
not	O
be	O
changed	O
by	O
the	O
function	O
run	O
.	O
</s>
<s>
The	O
'	O
=	O
'	O
(	O
assignment	O
)	O
operator	O
between	O
two	O
variables	O
of	O
the	O
same	O
structure	O
type	O
is	O
overloaded	O
by	O
default	B-General_Concept
to	O
copy	O
the	O
entire	O
content	O
of	O
the	O
variables	O
from	O
one	O
to	O
another	O
.	O
</s>
<s>
The	O
square	O
bracket	O
 [  ] 	O
and	O
the	O
round	O
bracket	O
(	O
)	O
can	O
be	O
overloaded	O
in	O
C++	B-Application
structures	I-Application
.	O
</s>
<s>
Like	O
the	O
assignment	O
(=	O
)	O
operator	O
,	O
they	O
are	O
also	O
overloaded	O
by	O
default	B-General_Concept
if	O
no	O
specific	O
declaration	O
is	O
made	O
.	O
</s>
<s>
Sometimes	O
programmers	O
may	O
want	O
their	O
variables	O
to	O
take	O
a	O
default	B-General_Concept
or	O
specific	O
value	O
upon	O
declaration	O
.	O
</s>
<s>
Member	B-Application
variables	I-Application
can	O
be	O
initialized	O
in	O
an	O
initializer	O
list	O
,	O
with	O
utilization	O
of	O
a	O
colon	O
,	O
as	O
in	O
the	O
example	O
below	O
.	O
</s>
<s>
This	O
is	O
more	O
efficient	O
for	O
class	O
types	O
,	O
since	O
it	O
just	O
needs	O
to	O
be	O
constructed	O
directly	O
;	O
whereas	O
with	O
assignment	O
,	O
they	O
must	O
be	O
first	O
initialized	O
using	O
the	O
default	B-General_Concept
constructor	O
,	O
and	O
then	O
assigned	O
a	O
different	O
value	O
.	O
</s>
<s>
Default	B-General_Concept
values	O
can	O
be	O
given	O
to	O
the	O
last	O
arguments	O
to	O
help	O
initializing	O
default	B-General_Concept
values	O
.	O
</s>
<s>
When	O
no	O
arguments	O
are	O
given	O
to	O
the	O
constructor	O
in	O
the	O
example	O
above	O
,	O
it	O
is	O
equivalent	O
to	O
calling	O
the	O
following	O
constructor	O
with	O
no	O
arguments	O
(	O
a	O
default	B-General_Concept
constructor	O
)	O
:	O
</s>
<s>
will	O
be	O
printed	O
when	O
the	O
default	B-General_Concept
Person	O
constructor	O
is	O
invoked	O
.	O
</s>
<s>
Default	B-General_Concept
constructors	O
are	O
called	O
when	O
constructors	O
are	O
not	O
defined	O
for	O
the	O
classes	O
.	O
</s>
<s>
However	O
,	O
if	O
a	O
user	O
defined	O
constructor	O
was	O
defined	O
for	O
the	O
class	O
,	O
both	O
of	O
the	O
above	O
declarations	O
will	O
call	O
this	O
user	O
defined	O
constructor	O
,	O
whose	O
defined	O
code	O
will	O
be	O
executed	O
,	O
but	O
no	O
default	B-General_Concept
values	O
will	O
be	O
assigned	O
to	O
the	O
variable	O
b	O
.	O
</s>
<s>
A	O
destructor	B-Language
is	O
the	O
inverse	O
of	O
a	O
constructor	O
.	O
</s>
<s>
when	O
an	O
object	O
of	O
a	O
class	O
created	O
in	O
a	O
block	O
(	O
set	O
of	O
curly	O
braces	O
"{}"	O
)	O
is	O
deleted	O
after	O
the	O
closing	O
brace	O
,	O
then	O
the	O
destructor	B-Language
is	O
called	O
automatically	O
.	O
</s>
<s>
Destructors	B-Language
can	O
be	O
used	O
to	O
release	O
resources	O
,	O
such	O
as	O
heap-allocated	O
memory	O
and	O
opened	O
files	O
when	O
an	O
instance	O
of	O
that	O
class	O
is	O
destroyed	O
.	O
</s>
<s>
The	O
syntax	O
for	O
declaring	O
a	O
destructor	B-Language
is	O
similar	O
to	O
that	O
of	O
a	O
constructor	O
.	O
</s>
<s>
If	O
not	O
declared	O
by	O
user	O
both	O
are	O
available	O
in	O
a	O
class	O
by	O
default	B-General_Concept
but	O
they	O
now	O
can	O
only	O
allocate	O
and	O
deallocate	O
memory	O
from	O
the	O
objects	O
of	O
a	O
class	O
when	O
an	O
object	O
is	O
declared	O
or	O
deleted	O
.	O
</s>
<s>
For	O
a	O
derived	O
class	O
:	O
During	O
the	O
runtime	O
of	O
the	O
base	O
class	O
constructor	O
,	O
the	O
derived	O
class	O
constructor	O
has	O
not	O
yet	O
been	O
called	O
;	O
during	O
the	O
runtime	O
of	O
the	O
base	O
class	O
destructor	B-Language
,	O
the	O
derived	O
class	O
destructor	B-Language
has	O
already	O
been	O
called	O
.	O
</s>
<s>
In	O
both	O
cases	O
,	O
the	O
derived	O
class	O
member	B-Application
variables	I-Application
are	O
in	O
an	O
invalid	O
state	O
.	O
</s>
<s>
In	O
many	O
current	O
C++	O
compilers	B-Language
,	O
integers	O
are	O
32-bit	O
integers	O
by	O
default	B-General_Concept
,	O
so	O
each	O
of	O
the	O
member	B-Application
variables	I-Application
consume	O
four	O
bytes	O
of	O
memory	O
.	O
</s>
<s>
However	O
,	O
the	O
compiler	B-Language
may	O
add	O
padding	B-Application
between	O
the	O
variables	O
or	O
at	O
the	O
end	O
of	O
the	O
structure	O
to	O
ensure	O
proper	O
data	B-Application
alignment	I-Application
for	O
a	O
given	O
computer	O
architecture	O
,	O
often	O
padding	B-Application
variables	O
to	O
be	O
32-bit	O
aligned	O
.	O
</s>
<s>
As	O
structures	O
may	O
make	O
use	O
of	O
pointers	O
and	O
arrays	O
to	O
declare	O
and	O
initialize	O
its	O
member	B-Application
variables	I-Application
,	O
memory	O
consumption	O
of	O
structures	O
is	O
not	O
necessarily	O
constant	O
.	O
</s>
<s>
It	O
is	O
applicable	O
only	O
for	O
the	O
classes	O
defined	O
using	O
the	O
keyword	O
struct	B-Application
or	O
class	O
.	O
</s>
<s>
As	O
stated	O
above	O
,	O
this	O
is	O
a	O
pointer	O
,	O
so	O
the	O
use	O
of	O
the	O
asterisk	B-Language
( *	O
)	O
is	O
necessary	O
to	O
convert	O
it	O
into	O
a	O
reference	O
to	O
be	O
returned	O
.	O
</s>
