From: Prochnow, C. <pro...@se...> - 2005-05-27 14:46:22
|
Am Freitag 27 Mai 2005 16:06 schrieb stephan beal: > i'm going through the code now, and i've got a couple of concerns: > > #1: > return static_cast<Factory&>( > FactoryBase::instance(typeid(InterfaceT).name(), > typeid(ContextT).name(), &createHook)); > > typeid::name() OFFICIALLY provides undefined behaviour. Under gcc i have > seen cases where typeid(T*).name() will return 2 different values, > depending on whether T comes from a DLL or was statically linked. > > i spent months fighting with typeid::name() in s11n before finally > dropping it altogether. i promise: it cannot be trusted at all. that's not fully true. it's right that gcc emits type_info objects in the compilation unit where they are used, therefore you cannot simply compare two type_info objects, cause gcc does a address comparsion. but when using type_info::name().. the type_info object returns the mangled c++ ABI name of the type which _must_ be the same in all compilation units. see this: http://gnu.open-mirror.com/software/gcc/faq.html#dso > Also, why do you need the static cast there? the static_cast is needed to up-cast the FactoryBase to the Factory. > #2: > > template <class TypeName> > void registerType(const std::string& key, TypeName) > { > registerFactory(key, &typeCreateHook<TypeName>); > } > > Why are we forced to pass a TypeName object? That is not at all suitable > for large types. If i'm not mistaken, it also means that we cannot > call registerType if TypeName is an incomplete type, where we can > (i think) if the user does not pass a TypeName object. i think we can make the second argument a const reference type. Greetings, Christian |