Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F78976900
type_casting.cpp
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Aug 24, 02:19
Size
520 B
Mime Type
text/x-c++
Expires
Mon, Aug 26, 02:19 (2 d)
Engine
blob
Format
Raw Data
Handle
20130557
Attached To
R9360 PCSC_git
type_casting.cpp
View Options
#include <iostream>
class
Animal
{
public
:
void
scream
()
{
std
::
cout
<<
name
<<
": AAAAA
\n
"
;
}
protected
:
std
::
string
name
;
};
class
Cat
:
public
Animal
{
public
:
void
scream
()
{
std
::
cout
<<
name
<<
": MIAOU
\n
"
;
}
};
class
Dog
:
public
Animal
{
public
:
void
scream
()
{
std
::
cout
<<
name
<<
": OUAFF
\n
"
;
}
};
void
casting
()
{
Cat
c
;
Animal
*
ptr
=
&
c
;
ptr
->
scream
();
}
void
makeItScream
(
Animal
&
a
)
{
// do not know if 'a'
// is Cat or Dog
a
.
scream
();
}
int
main
()
{
Cat
c
;
makeItScream
(
c
);
}
Event Timeline
Log In to Comment