   I need code tested on other compilers...
  Can you try compiling this code. Then post the compiler name, compiler version and any errors/warnings (if any) you get.   #include <iostream>#include <cstdlib>using namespace std;#define smart(clazz) clazz##_smart_#define SMART_CLASS(clazz)\    class smart(clazz);   \    typedef SmartObject<smart(clazz)> clazz;  \    class smart(clazz)class NullPointerException { public: NullPointerException() {} };template<class T>class PointerReferences{long count;T p;public:PointerReferences() : count(0) {}void incRef() { count++; }void decRef() { delete this; }void operator delete (void *o) {PointerReferences<T> *t = static_cast<PointerReferences<T>* >(o);if (!t) return;if (t->count > 0)t->count--;if (t->count <= 0)free(t);}T *getPointer() { return &p }};template<class T>class SmartObject{PointerReferences<T> *p;void _assign(PointerReferences<T> *o){if (p)p->decRef();p = o;if (p)p->incRef();}public:SmartObject() : p(0) {}//SmartObject(T *o) : p(0) { this->_assign(o); }SmartObject(const SmartObject<T> &o) : p(0) { *this = o; }SmartObject(const SmartObject<T> *o) : p(0) { *this = o; }virtual ~SmartObject() { *this = 0; }//AssignmentSmartObject<T> &operator = (const SmartObject<T> &o) {if (o.p)this->_assign(const_cast<PointerReferences<T>* >(o.p));elsethis->_assign((PointerReferences<T> *)0);return *this;}SmartObject<T> &operator = (const SmartObject<T> *o) {//HACK: Theoretically SmartObject<T>* it is actually a PointerReferences<T>* in disguise.if (o)this->_assign(reinterpret_cast<PointerReferences<T>*>(const_cast<SmartObject<T>* >(o)));elsethis->_assign((PointerReferences<T> *)0);return *this;}operator T *() { return p->getPointer(); }//Pointer to memberT &operator *() { if (p && p->getPointer()) return *(p->getPointer()); else throw NullPointerException(); }T *operator ->() { if (p && p->getPointer()) return p->getPointer(); else throw NullPointerException(); }//Comparisonbool operator !() { return !p; }bool operator ==(const T *o) { return (p->getPointer() == o); }bool operator !=(const T *o) { return (p->getPointer() != o); }operator bool() { return (p != 0); }//New operatorvoid *operator new (size_t sz) { return new PointerReferences<T>(); }};SMART_CLASS(testClass){public:    smart(testClass)() {   std::cout << "\nAllocating 65000 integers.";    }    virtual ~smart(testClass)() {   std::cout << "\nDestroying 65000 integers.";    }    void run() {   std::cout << "\nRunning...";    }};SMART_CLASS(class2){public:    smart(class2)() {   std::cout << "\nCreating new class2";    }    ~smart(class2)() {   std::cout << "\nDestroying class2";    }};int main(int argc, char **argv){    try    {   testClass t = new testClass;   t->run();   t = new testClass;   t->run();   t->run();   t = 0;   //only condition that I can''t handle   new class2;    }    catch (NullPointerException)    {   cout << "\nNullPointerException!";    }    catch (...)    {   cout << "\nUnknown Exception!";    }    cin.ignore();    return 0;}Thanks.btw, does this code prove I''m crazy?!!   <!-- ................................ -->u r what u bcomeMy (XHTML 1.0 Strict) Website
  You''re suppose to catch by reference, if not const reference.I think there is a simpler way (if not just a more direct way) to accomplish what you want.  Could clearify what you are trying to accomplish? ;  I''m just trying to make a way to simplifying managing pointers (not that I have a big problem with that...), by using automatic memory managment with very little overhead. ;  boost::shared_ptrboost::scoped_ptrboost::weak_ptret. al.   - Magmai Kai HolmlorNot For Rent[Look for information | GDNet Start Here | GDNet Search Tool | GDNet FAQ | MSDN RTF[L] | SGI STL Docs | STFW | Asking Smart Questions ][Free C++ Libraries | Boost | ACE | Loki | MTL | Blitz++ | wxWindows| Spirit(xBNF)][Free C Libraries | zlib ]