Before C++, java or c#, C offers the struct. This is a true-blue value type. When you put a struct type variable on the LHS, the entire struct instance with all the fields are cloned bitwise.
If one of the fields happens to be a pointer like a c_str, then the address inside the pointer field is copied.Beside pbclone, you can also work with a pointer to struct -- a bit advanced.
-----------
In C++, the struct is backward compatible with C -- pbclone by default.C++ also added lots of features into the struct construct. It's essentially identical to the class except members are public by default.
Therefore, c++ class/struct instances follow value semantics (pbclone) by default
-----------
In java, there's only class, no struct. Any class instance is pbref -- simple and clean. You never get bitwise copy with java class instances.------------
No comments:
Post a Comment