Wednesday 15 September 2010

Java's casting and C++'s casting -


I came from C ++ and know only some Java, but there is one thing that I completely Do not think about casting. In C ++, we have Java, we cast through the primitive type and object type (known as Boxing and Unboxing), primitive types, using the class function , And sometimes we do casting between unchecked castings. Is there a direct mapping in the C ++ casting system from Java's casting system? Are they equal? Or is there something that is unique on one side?

If you know C ++, the Java object model should be easily explained by related type The class types of Java variables are reference for dynamically created objects. An initial Java variable T x = new T (); matches the C ++ pointer: T * px = new T;

In Java, all category types are derived from the polymorphus type object , and thus all pointers can be used for RTTI: all Java class- Type variables can use dynamic_cast in C ++, then (s) x of Java with dynamic_cast corresponding code. S * & gt; (Px) In C ++, with a single failure mode, a null result indicates that dynamic types are not related ''.

All other C ++ potter dots are unsafe and do not have the equivalent in Java. I do not know that Java has scalar conversions like integer-to-floating point; If so, they will be associated with C ++ conversions.

Boxing and primitive types are a separate and unrelated issue. If you want something like this in C ++, you have any type of template & lt; Typename T & gt; Structure-to- T structure box with operator

No comments:

Post a Comment