An Adapter Solution
Long long ago, there were one couple who lived in a very mystical village. They had two children,but their children couldn't speak. The worst thing was that nobody knew they were girl or they were boy, even the couple!
class
Father
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}
;
![](/Images/OutliningIndicators/None.gif)
class
Mother
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}
;
![](/Images/OutliningIndicators/None.gif)
class
Child1 :
public
Father,
public
Mother
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}
;
![](/Images/OutliningIndicators/None.gif)
class
Child2 :
public
Father,
public
Mother
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
}
;
![](/Images/OutliningIndicators/None.gif)
Then one day, an old man, from very far away, nobody knew where he came from and what he would to do, came to the village. It was very strange that the whole village became exciting after he stayed there only for a day. That's because he found the sex of the couple's children, and he also made the two little to speak, because he had magic tools:
enum
SEX
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
GRIL,
BOY
}
;
![](/Images/OutliningIndicators/None.gif)
class
NewFound
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public
:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void
Speak()
{}
}
template
<
class
P,
class
N, SEX sex
>
class
ChildT :
public
P,
public
N
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public
:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
SEX getSex()
{
return
sex;}
}
So the two children look like as the following:
typedef ChildT
<
Child1, NewFound, BOX
>
Son;
typedef ChildT
<
Child2, NewFound, GIRL
>
Girl;
![](/Images/OutliningIndicators/None.gif)
Son son;
SEX sex
=
son.getSex();
son.Speak();
![](/Images/OutliningIndicators/None.gif)
Girl girl;
sex
=
girl.getSex();
gril.Speak();
As time gone by, the couple had another girl. The first day of her life, she learned to speak, and the second day, she learned the ability to fly!!! What a strange girl! You may ask whether she was an angel. Maybe only the god knows that.
class
NewGirl :
public
ChildT
<
Father, NewAblity, GIRL
>
,
public
Mother
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public
:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void
Fly()
{}
}
or
class
NewGirl :
public
ChildT
<
Mother, NewAblity, GIRL
>
,
public
Father
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
public
:
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
void
Fly()
{}
}
To be continued?