Skal det så forstås sådan, at C++ er lavet af en dansker? Det må det vel næsten skulle. Men vi danskere er jo heller ikke HELT dårlige 
Ja, oprindeligt er det lavet af en dansker. Det har udviklet sig en del siden og der er kommet flere *gode* ting til.
T* t = (T*) ptr;
En af de ting, der er tilføjet er en erstatning for den gamle C-style cast (se eksempel ovenfor) og man skal derfor i stedet bruge nedenstående.
T* t = reinterpret_cast<T>(ptr);
T* t = static_cast<T>(ptr);
T* t = const_cast<T>(ptr);
T* t = dynamic_cast<T>(ptr);
The C++ casting operators are intended to provide a solution to the shortcomings of the old C-style casts by providing:
* Improved syntax. Casts have a clear, concise, although somewhat cumbersome syntax. This makes casts easier to understand, find, and maintain.
* Improved semantics. The intended meaning of a cast is no longer ambiguous. Knowing what the programmer intended the cast to do makes it possible for compilers to detect improper casting operations.
* Type-safe conversions. Allow some casts to be performed safely at run-time. This will enable programmers to check whether a particular cast is successful or not.
Indlæg senest redigeret d. 02.02.2007 17:04 af Bruger #10448