Create
a class called
bird
that can
fly( )
and a class
rock
that can’t. Create a
rock
object, take its address, and assign that to a
void*.
Now take the
void*,
assign it to a
bird*,
and call
fly( )
through that pointer. Is it clear why C’s permission to openly assign via
a
void*
is a “hole” in the language?
Create
a class containing a
const
member that you initialize in the constructor initializer list and an untagged
enumeration that you use to determine an array size.
Create
a class with both
const
and non-
const
member functions. Create
const
and non-
const
objects of this class, and try calling the different types of member functions
for the different types of objects.
Create
a function that takes an argument by value as a
const;
then try to change that argument in the function body.
Prove
to yourself that the C and C++ compilers really do treat constants differently.
Create a global
const
and use it in a constant expression; then compile it under both C and C++.