Have you even tested this? It is certainly not going to work like you intended
Some things that are just wrong:
cRefCounted::RefRemove(): it does a 'delete this' but cRefCounted doesn't have a virtual destructor. Therefore, any subclass of cRefCounted will never get destructed appropriately. It is always a good idea to include a virtual destructor if your class is going to be derived from. You may want to make this destructor private if you only want a class to be constructed using new(), rather than a local/global or as a member of another class. You can make it protected to leave this decision to the derived class.
cRefCounted::type() function is also flawed. It uses typeid(this), but 'this' is a pointer so it will always yield 'cRefCounted*'. If you want to want an actual runtime type lookup, you should dereference the pointer. Note that this currently won't work either as cRefCounted doesn't have a vtable (and therefore no type information), but adding the previously suggested virtual destructor should solve this.
tHandle::init(): a static_cast will never fail and never throw a bad_cast. If you want runtime type checking, use dynamic_cast. But this currently fails to compile because dynamic_cast needs type information, which a cRefCounted doesn't have as it doesn't have a vtable
. Another thing is that init() does not remove a reference on the previous held object. If I have a tHandle that points to A and I then let it point to B using tHandle::operator=(), A's refcount will never get decreased.
I would let the tHandle constructor take a T* rather than a cRefCounted*, to make it compile-time type safe. Of course, bad use will cause a runtime exception if you implement the init() using a dynamic_cast, but having a compile-time error will let you catch the error earlier. Also, C++'s design perspective has the overall paradigm that the users choose when they want to pay the price. A dynamic_cast is costlier than a static_cast. Create your own casting functions that implement both static_cast and dynamic_cast on the actual pointers.
template<class T1, class T2> tHandle<T1> dynamic_handle_cast(const tHandle<T2> & handle)
template<class T1, class T2> tHandle<T1> static_handle_cast(const tHandle<T2> & handle)
You may want to add a templated tHandle conversion constructor to be able to implicitely contruct a tHandle<A> from a tHandle<B> if B derives from A. You can use SFINAE tricks to only include that constructor if B actually is implicitely convertable to A which I don't want to delve into right now, or you can simply add the ctor and just let the compiler give an error when the actual template instantiation turns out to be incorrect (when B doesn't actually derive from A), in which case the user gets a vager error message but the net effect is the same.
There's no need to make tHandle::~tHandle() virtual. tHandle is a class that will probably not ever be derived from. The extra vtable only costs extra performance and memory.
Also, keep in mind the current implementation is not thread-safe. This may suite your needs, but it is something to remember