I want to use passed template parameter as string. Is it possible?
T is class, what do i need to change to get that code work?
void registerClass(const std::string &name, Handler *handler);
template<class T>
void registerClass() {
registerClass( "get T as string", new DefaultHandler<T>());
}
The closest you can get to get a type as a string is with
typeid( T )->name(). However, there is no standarization for type names, so you can’t trust in getting a valid name from it. A standard compliant implementation may very well return empty strings for all type names.