Lattice C++
Steve,
C++ covers a lot of ground, so I'll only hit a few highlights.
1. Overloaded functions
Multiple functions can share the same name as long as their argument lists
are different:
int abs(int);
float abs(float);
Calling abs(2.01) would cause the compiler to automatically call the float
version. No more need to differentiate between abs() and fabs().
2. Call-by-reference
foo(int& a) { a += 3 };
int d = 0;
foo(d); // d now equals 3
3. User-defined classes
C++ has expanded the C structure to include not only data-elements, but
also all the methods allowed to operate on those elements. These new
classes (as they are called) allow the user to define all the standard C
operators (+,-,*,++,<<=,->,[],etc.) for the class, as well as constructors
and destructors which tell the compiler how to initialize the object when
first declared and release the object when it goes out of scope. Further,
classes allow elements (and methods) to be declared public (anyone can
access them) or private (only accessible within the class).
As an example, one of my first projects in C++ was building a list class.
The class handled most of the basic list functions (insert, delete, empty,
next, prev, first, last), but in order to get it done quickly, I actually
used a static array for storage. I then hacked my netnews reader to use
the new list stuff. Once that was running, I decided the list class needed
to be dynamic, so I modified the list code accordingly. However, since I
didn't change the public portion of the list class, the only module I
needed to change was the list module. Recompiled and everything worked
great.
[ MORE ]