hjk41的日志

Avatar

More Effective C++ 2: Prefer C++-style casts

There are four types of C++-style casts:
dynamic_cast
static_cast
const_cast
reinterpret_cast

They are used like this:


double a=1.00;
int b=static_cast<int>(a);

static_cast is quite the same as C-style cast.
dynamic_cast is for navigating inheritance hierachies. It can not be applied to types that have no virtual funcitons.
const_cast is for casting away the const
reinterpret_cast is usually used on function pointers

评论已关闭