5 implicit conversions by c++ compiler – big 4

See also post on the “same” topic. There are too many such implicit things to list in one blog. This one is about the dtor, copy-ctor, assignment operator + ctor — the big 3 + 1.
# MyClass myObj; // calls the default ctor
# MyClass myObj5[5] // ditto
# op-new first argument is always a size_t, but when you invoke it you never pass pass in size
# assigning to an existing reference var of MyClass calls the assignment operators implicit
          refVar2.operator=(….) //because reference variables can’t be reseated

# per-class overloaded operator new and operator delete are implicitly static, always. ARM P283
** overloaded op new is (implicitly) inherited

# Say your copy ctor is invoked (often implicitly;-). Therein you need to clone a FIELD of type T. If you don’t use the field initializer syntax, then the copier first calls T’s no-arg ctor to “make room” for the field, then calls T’s operator= to modify its state.

# when you new up a Derived object on heap, and Base class has an operator new, you would use that (implicitly inherited) operator-new unless Derived class redefines (“override” is wrong term) operator-new.
** when you new up a Umbrella object on heap, and the object has a non-ref (not pointer either) field of type Base, you would ignore whatever operator-new Base has. You use either “::operator new” or the Umbrella’s own operator-new to grab a sizeof(Umbrella) chunk. That’s all the memory you need. Part of it will be constructed as a Base object. See [[more effC++]]


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