The most significant difference between Java and C + + is in the processing of objects. In Java, an object variable is internally treated as a pointer. The Java literature indicates that object variables are referenced, but they are not identical to references in C + +. The so-called reference is a thing between a pointer and a variable.
---------is the difference between this essence, will be a lot of Java,ok code, and then C + + is really wrong. The reference concept------Java and the C + + reference are not the same meaning. Java references are similar to C + + pointers.
- In a C + + declaration, a class name can be used to declare a value for such an object. There is no way to do this in Java. Objects in Java are not values. In the Java declaration, a class name declares a reference to an object of this class. The equivalent of this in C + + is to use "*" to declare a pointer.
- In C + +, "." The operator accesses an object as a left-hand parameter to access the member of the object. Because the object is not a value in Java, all objects are accessed by reference, which is just not possible in Java. In Java, the "." operator accesses a member of the object as a left-hand argument. In C + + This approach is equivalent to "--".
Example:
C + +: String a = Null--error error occurs because the default constructor for the string source code is not supported. If the string default constructor support, it is also possible (because he compiled is OK, stating that the syntax is not a problem, when running an error, that the constructor does not support it)
String default constructor Source code:
__clr_or_this_call basic_string (const _elem *_ptr)
: _mybase ()
{//construct from [_ptr, <null>]
_tidy ();
Assign (_PTR); Because _ptr is NULL, there's an error back here.
}
string* a =null---OK pointer can be empty
Java String a=null----OK java, an object variable is internally treated as a pointer
Reference documents:
Http://zh.wikipedia.org/wiki/Java%E5%92%8CC%2B%2B%E7%9A%84%E5%B0%8D%E7%85%A7
http://bbs.csdn.net/topics/190137939
The difference between C + + and Java