Calling constructors in c++ without new -
i've seen people create objects in c++ using
thing mything("asdf");
instead of this:
thing mything = thing("asdf");
this seems work (using gcc), @ least long there no templates involved. question now, first line correct , if should use it?
both lines in fact correct subtly different things.
the first line creates new object on stack calling constructor of format thing(const char*)
.
the second 1 bit more complex. following
- create object of type
thing
using constructorthing(const char*)
- create object of type
thing
using constructorthing(const thing&)
- call
~thing()
on object created in step #1
Comments
Post a Comment