topical media & game development
professional-program-12-Casts-StaticCast.c
? /
professional-program-12-Casts-StaticCast.c
class Base
{
public:
Base() {};
virtual ~Base() {}
};
class Derived : public Base
{
public:
Derived() {}
virtual ~Derived() {}
};
int main(int argc, char** argv)
{
Base* b;
Derived* d = new Derived();
b = d; // Don.t need a cast to go up the inheritance hierarchy
d = static_cast<Derived*>(b); // Need a cast to go down the hierarchy
Base base;
Derived derived;
Base& br = base;
Derived& dr = static_cast<Derived&>(br);
int i = 3;
double result = static_cast<double>(i) / 10;
return (0);
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.