[comp.lang.c++] Two short questions and one half-baked idea about overloading "dot"

steve@taumet.com (Stephen Clamage) (04/04/91)

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