A
Andrea Crotti
Supposing that I have a class which takes a reference to an object in
the constructor.
MyClass:Myclass(const Other& obj)
Now I would to be able to do the following
Other obj(...);
MyClass *cl = new MyClass(obj);
and when I do a
delete cl;
Also the memory allocated by the first object gets freed.
Is that possible?
It would be fairly easy if I declare ~Myclass and I pass a pointer
instead of a reference, but it adds some more complexity which would
be nice to avoid.
If you know if it's possible somehow I would be glad to know it...
At the moment I'll just leave it like this because I don't want to do
premature optimizations, but this optimization I'm sure will be
necessary in a short time.
the constructor.
MyClass:Myclass(const Other& obj)
Now I would to be able to do the following
Other obj(...);
MyClass *cl = new MyClass(obj);
and when I do a
delete cl;
Also the memory allocated by the first object gets freed.
Is that possible?
It would be fairly easy if I declare ~Myclass and I pass a pointer
instead of a reference, but it adds some more complexity which would
be nice to avoid.
If you know if it's possible somehow I would be glad to know it...
At the moment I'll just leave it like this because I don't want to do
premature optimizations, but this optimization I'm sure will be
necessary in a short time.