Ryan's District Boards

Computer, programming, and webmaster help , support , tips and tricks => Tutorials Zone! => Internet webmaster computer programming technology tips and tricks => C++ / C / C# ....Tutorials => Topic started by: ben2ong2 on October 07, 2006, 03:56:19 AM

Title: C++ tips - Preventing automatic variables of a class
Post by: ben2ong2 on October 07, 2006, 03:56:19 AM
PROBLEM: hlf@nic.cerf.net (Howard Ferguson),

I wish to define a class in a library which the library user
can create by dynamic allocation via the new operator, but
I want to prevent him from creating automic instances.


RESPONSE: nikki@trmphrst.demon.co.uk (Nikki Locke), 6 Jan 93

Leave the constructors public. Make the DESTRUCTOR private. Provide an
inline member function ...

   void destroy() { delete this; }

Users have to call destroy instead of delete, but they won't be able to
create automatic, static or extern objects of the class.