On Fri, Feb 28, 2003 at 05:36:31PM +0100, Murray Cumming Comneon com wrote: > > > Class Node : public xmlpp::Node<Glib::ustring> > > > > wouldn't this still require the full inclusion of the > > xmlpp:Node<> class template? > > Yes, I guess people would still be using the inherited methods as templates > unless we reimplemented them too. Yes, and to instantiate an xmlpp_ustring::Node would require the full definition of xmlpp::Node<...> (in order to know the size of the object) which would require the template definition, i.e. the header > > I think for this to work the > > underlying Node<Glib::ustring> would have to be hidden behind > > a "compiler firewall" using the pimpl idiom. > > I'm not sure that pimpl is necessay. Just calling the templated methods from > the untemplated derived methods would probably do it. But I haven't given it > that much thought. Your way would certainly work, and is no worse really. Hmm, if I follow you, what object does the non-template class call those methods on? It would have to be a member or a base class, but both of those would require the full definition of the template class to be visible. This is exactly what the pimpl is for; with the downside of having to implement all methods twice, which as you say... > Yes. Unpleasant. > > > To make even more work, a similar wrapper could be done for > > other common params (e.g. QString) and included in the > > libxml++.a library, allowing users of other tmeplate > > instantiations to also drop in a new library without recompiling. > > I think we would need separate libxml++_* libraries unless we want libxml++ > to depend on both glibmm and Qt. Ah, yes. The library would then be: A set of headers containing class templates, and ... a set of headers and libraries for each specific instantiation. *.h xmlpp_glib/*.h libxml++_glib.a libxml++_glib.so xmlpp_qt/*.h libxml++_qt.a libxml++_qt.so xmlpp_xxx/*.h libxml++_xxx.a libxml++_xxx.so Good thing I already had a headache before I started thinking about this ;-) > > > More importantly, I'm not sure whether our inheritance/polymorphism > > > would still work. Is Element<Glib::ustring> still an instance of > > > Node<Glib::ustring>? > > > > yes: > > Sorry, bad example. Yes, is probably would work for simple typedefs, but I > don't think it would work for derived classes, such as your pimpl technique. Should do: class Node { void* pimpl; // points at a Node<s> }; class Element : public Node { void* pimpl; // points at an Element<s> which has a Node<s> base }; Apologies if I've still misunderstood. jon P.S. I've attached a tarball with a demo of this technique. Un-tar and type "make" (or "gmake" on non-GNU systems) -- I listen a lot and talk less. You can't learn anything when you're talking. - Bing Crosby
Attachment:
pimpl.tar.gz
Description: application/tar-gz