CS253 IQ 07
Show Main.IQ07 as a slide show.
What problem do virtual functions deal with?
- Fireball
- Invisibility
- Polymorphism
- Regeneration
- Simulacrum
Which of these is correct?
class Base { };
class Derived : public Base { };
Base *b = …;
Derived *d = …;
b = dynamic_cast<Base *>(d);
b = dynamic_cast(Base *, d);
b = dynamic_cast(d);
d = dynamic_cast(b);
d = dynamic_cast<Derived *>(b);
d = dynamic_cast(Derived *, b);
Any problems with this code?
#ifndef FOO_H_INCLUDED
#include "otherfile.h"
#include <string>
class Foo {
…
};
#define FOO_H_INCLUDED
#endif
- It’s fine.
- The
#ifndef
should be #ifdef
.
- The
define
is in the wrong place.
- It’s unnecessary—include guards are no longer required
in modern compilers.
Bit Manipulation
What’s the best way to find out if bit #7 (where bit #0 is the LSB)
of the int v
is set?
if (v.bit(7))
if (v & 00000080)
if (v && (1 << 7))
if ((v>>7) & 01)
if ((v<<24) < 0)