Proper way of casting pointer types

For convertible pointers to fundamental types both casts have the same meaning; so you are correct that static_cast is okay. When converting between some pointer types, it’s possible that the specific memory address held in the pointer needs to change. That’s where the two casts differ. static_cast will make the appropriate adjustment. reinterpret_cast will not. … Read more

Why doesn’t this reinterpret_cast compile?

In C++ reinterpret_cast can only perform a specific set of conversions, explicitly listed in the language specification. In short, reinterpret_cast can only perform pointer-to-pointer conversions and reference-to-reference conversions (plus pointer-to-integer and integer-to-pointer conversions). This is consistent with the intent expressed in the very name of the cast: it is intended to be used for pointer/reference … Read more

Should I use static_cast or reinterpret_cast when casting a void* to whatever

Use static_cast: it is the narrowest cast that exactly describes what conversion is made here. There’s a misconception that using reinterpret_cast would be a better match because it means “completely ignore type safety and just cast from A to B”. However, this doesn’t actually describe the effect of a reinterpret_cast. Rather, reinterpret_cast has a number of … Read more

When to use reinterpret_cast?

The C++ standard guarantees the following: static_casting a pointer to and from void* preserves the address. That is, in the following, a, b and c all point to the same address: int* a = new int(); void* b = static_cast<void*>(a); int* c = static_cast<int*>(b); reinterpret_cast only guarantees that if you cast a pointer to a … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)