Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!uwm.edu!spool.mu.edu!uunet!taumet!steve From: steve@taumet.com (Stephen Clamage) Newsgroups: comp.lang.c++ Subject: Re: Two short questions and one half-baked idea about overloading "dot" Keywords: c++, templates, persistent, dot Message-ID: <649@taumet.com> Date: 4 Apr 91 00:15:44 GMT References: <324@secola.Columbia.NCR.COM> Distribution: usa Organization: Taumetric Corporation, San Diego Lines: 49 jmartin@secola.Columbia.NCR.COM (John Martinez) writes: >Also, if it's not too much trouble, what are templates? My copy of the ATT c++ >docs lists it in the table of contents as something "experimental" and has a >"placeholder" chapter about it ... A possible definition of templates is in the ARM (Ellis and Stroustrup, "The Annotated C++ Reference Manual"). This write-up may not be precisely what will wind up in the final ANSI C++ Standard (or in any C++ compiler release), but will probably be very close. >Third, since I'm posting anyway (please ignore this if it is an old argument) - >I've been following the overloadable "." discussion... > In PASCAL, there is a notion of a structure called a variant >record... [suggests a smart operator-dot to enforce correct use of > variant records]. A better way to enforce correct use of variant records in C++ is to use derived classes and virtual functions. You always get what you would expect with little or no intervention needed. Instead of class Employee { ... enum Emp_kind { part_time, hourly, salaried, executive }; Emp_kind kind; union { struct { ... } s_part_time; // part-time stuff struct { ... } s_hourly; // hourly stuff struct { ... } s_salaried; // salaried stuff struct { ... } s_executive; // exective stuff }; }; use class Employee { ... // basic employee stuff virtual compute_paycheck(); }; class part_time : public Employee { ... // part-time employee stuff compute_paycheck(); ... } class hourly : public Employee { ... compute_paycheck(); ... } class salaried : public Employee { ... compute_paycheck(); ... } class executive : public salaried { ... compute_paycheck(); ... } No variant records, no special operator-dot, it all just works right. -- Steve Clamage, TauMetric Corp, steve@taumet.com