Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!snorkelwacker.mit.edu!bloom-picayune.mit.edu!bloom-beacon!eru!hagbard!sunic!chalmers.se!appli!niklas From: niklas@appli.se (Niklas Hallqvist) Newsgroups: comp.lang.c++ Subject: Re: solution to implementing parameterized classes Message-ID: <1393@appli.se> Date: 15 Jun 91 06:54:31 GMT References: <1991Jun9.013306.4462@cs.sfu.ca> <1991Jun9.204515.18040@ms.uky.edu> <25349@well.sf.ca.us> <1991Jun11.183133.11458@auto-trol.com> <14976@exodus.Eng.Sun.COM> Organization: Applitron Datasystem AB, GOTHENBURG, SWEDEN Lines: 40 chased@rbbb.Eng.Sun.COM (David Chase) writes: >mattel@auto-trol.com (Matt Telles) writes: >>nagle@well.sf.ca.us (John Nagle) writes: >>> As does the notion that "(void *)" should be a normal part of programming. >> FINALLY! Someone else that dislikes the idea of a pointer to nothing ... >>Can't we define a type called generic???? (You know, like a generic pointer). >I'm afraid you missed the point. If the only way to write reusable >code turns out to be to use "generic" (or "void *") everywhere, what's >the point of pretending to have a type checker? People griped about >this for Cedar Mesa and Modula-2+, but at least there they had >run-time checking of type conversions from generic-to-specific. Maybe I'm missing the point here too. You still can have a strongly typed language, as long as you carefully encapsulate all type-unsafe casts into small classes where a reader easily can see that you don't lie. Example follows: template class Stack_of_p : Stack { public: void push(T* t) { Stack::push(t); } T* pop() { return (T*)Stack::pop(); } //... }; It's easy to see that every Stack_of_p::push(T*) implies a cast from T* to void*, and thus the reverse cast in Stack_of_p::pop() is type-safe! (In case the usual stack semantics apply, of course...) Niklas -- Niklas Hallqvist Phone: +46-(0)31-40 75 00 Applitron Datasystem Fax: +46-(0)31-83 39 50 Molndalsvagen 95 Email: niklas@appli.se S-412 63 GOTEBORG, Sweden mcsun!sunic!chalmers!appli!niklas