* nikki:
Hi all!
I have alittle question.
What is the code like to make sure that if we create an object of a
class dynamically , it is allocated memory but not when a static object
of the same class????
If you mean, "how do I ensure that objects of my class are dynamically
allocated?":
Make the destructor 'private' or 'protected', and provide an accessible
function that calls 'delete'. This can be an ordinary member function
(simple) or e.g. a friend template function (general).
This way you don't have to provide one factory function per constructor,
which is less work and better for maintenance (adding, removing or
changing constructors requires no parallell maintenance of factory
functions, and deriving from the class can be easier).
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?