Skip to content

Commit

Permalink
RTTI
Browse files Browse the repository at this point in the history
two styles
  • Loading branch information
feihun1 committed Jun 19, 2017
1 parent c4125b3 commit e33f0ff
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions dynamic_cast&&typeid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Grand *pg;
Superb *ps;
for (int i=0;i<5;i++)
{
pg=GetOne();
pg->Speak();
if (ps=dynamic_cast<Super *ps>(pg))
ps->Say();
}

equal to:

Grand *pg;
Superb *ps;
for (int i=0;i<5;i++)
{
pg=GetOne();
pg->Speak();
if (typeid(Superb)==typeid(*pg))
{
ps=(Superb *)pg;
ps->Say();
}
}

0 comments on commit e33f0ff

Please sign in to comment.