assignment in 5 kinds of c++ variables

— ptr to primitive or ptr to class type
float* newPtr = oldPtr; // copies address of the wrapped object. This is what happens in a default copier and assignment

— primitive ref assignment
overwrite object State, just like java primitive assignment.

Note if a class has a ref field and a ptr field, they behave differently during the field-by-field class assignment!

— class type ref assignment
MyClass& newRef = someRef;
newRef = oldRef; // overwrites object state, field by field

— primitive nonref assignment
obvious

— class type nonref variable
MyClass v; // ctor
v = v2; // field by field state overwrite by assignment operator

——various types of variables to look at
) Primitives ^ class types
) Pointer(and ref) ^ nonref types

A very detailed stroke-by-stroke on assignment overload — http://icu-project.org/docs/papers/cpp_report/the_anatomy_of_the_assignment_operator.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s