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

— 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 —

Leave a Reply

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

You are commenting using your 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