CB> Hi!
CB> There are a few parts of C++ that confuse me, and I was
CB> wondering if some kind people could explain them to me
CB> (not so much what they do, but how they're done):
CB> 1) the ? : thing
CB> an example I spotted in a message in here: regs.x.bx ==
CB> 0xffff ? 2 : regs.x.bx
it's kind of an if..then..else, but not for flow control... it's rather for
expressions
CB> 2) templates
instead of writing this:
int max (int a, int b) { return a>b? a: b; }
long max (long a, long b) {return a>b? a: b; }
float max (float a, float b) {return a>b? a: b; }
... (ad nauseam)
you write:
template max (Any a, Any b) { return a>b? a: b; }
and then, it's automatically done for all types.
CB> 3) deriving classes
when you have several similar classes, helps prevent repetition. One class is
a base one; each class derived from it inherits all its features and you add
what you want. (talking about both code & data, btw).
matju
--- Maximus 3.01
---------------
* Origin: BitByters BBS, Rockland ON, Can. (613)446-7773 v34, (1:163/215)
|