C++
- A static_cast can be used to explicitly convert between related pointer types, such
as void* and double* - reinterpret_cast can cast between unrelated types, such as int and double* .
- const_cast can “cast away const .”
For example:
int* pi = static_cast<int*>(pv);
Register* in = reinterpret_cast<Register*>(0xff);
void f(const Buffer* p)
{
Buffer* b = const_cast<Buffer*>(p);
// . . .
}
Go Cast
There are three methods as follows:
- use ()
example: var b float64 = float64(a) - stcrcov package
example: num, err := strconv.Atoi(str) - interface{} type
example: str, ok := i.(string)