C
ceo
Hi there,
I'm reffering to a text that says following:
"To summarize: When a copy of an object is generated because it passed
to a function, the object's constructor function is not called.
However, when the copy of the object inside the function is destroyed,
its destructor is called.
By default, when a copy of an object is made, a bitwise copy occurs.
This means that the new object is an exact duplicate of the original.
The fact that an exact copy is made can, at time, be a source of
trouble. Even though objects are passed to functions by means of the
normal call-by-value parameter passing mechanism, which, in theory,
protects and insulates the calling argument. For example, if an object
used as an argument allocates memory and frees that memory when it is
destroyed, then its local copy inside the function will free the same
memory when its destructor is called. This will leave the original
object damaged and effectively useless."
Could someone give me an example that will damage the original object?
Thanks,
Ceo
I'm reffering to a text that says following:
"To summarize: When a copy of an object is generated because it passed
to a function, the object's constructor function is not called.
However, when the copy of the object inside the function is destroyed,
its destructor is called.
By default, when a copy of an object is made, a bitwise copy occurs.
This means that the new object is an exact duplicate of the original.
The fact that an exact copy is made can, at time, be a source of
trouble. Even though objects are passed to functions by means of the
normal call-by-value parameter passing mechanism, which, in theory,
protects and insulates the calling argument. For example, if an object
used as an argument allocates memory and frees that memory when it is
destroyed, then its local copy inside the function will free the same
memory when its destructor is called. This will leave the original
object damaged and effectively useless."
Could someone give me an example that will damage the original object?
Thanks,
Ceo