CompuServe Thread

#Lattice C++

8 messages in this thread
#88262From: Alan EngebretsonFeb 2, 1990 7:45 PM
I'm thinking of getting Lattice's C++ compiler. Does anyone out there have it?
#88263From: Thomas HoladayFeb 2, 1990 7:51 PM
I own Lattice's C++. Are you familiar with C++ the language, and are curious about Lattice's implementation? Or is it pure hobbyist speculation?
#88280From: Dave LoveFeb 2, 1990 8:43 PM
I've had it for a while now. All in all, it is a very good port of C++ V1.2, particularly when combined with Lattice's 5.02 compiler (C++ comes with the 4.0 compiler). If you're new to C++, or normally use C++ V1.2 elsewhere, then I recommend it highly. On the other hand, if you're up to speed on C++ V2.0 (AT&T's latest), then you might want to hold off. I use V2.0 at work and find switching back to 1.2 to be more trouble than it's worth. Hope this helps. – Dave
#88399From: Steve AhlstromFeb 3, 1990 2:59 PM
Dave, I know nothing about C++, but, as a C derivative, I am intrigued about it -but not enough to pop $250 for it. Can you tell me a bit about it? What exactly does "object oriented" mean in how a C programmer would relate to it? -sja
#88435From: Thomas HoladayFeb 3, 1990 6:30 PM
Simple case: class Window { private: char *name; short xpos, ypos, xwid, ywid ; … public: Window() ; Window(char *s); ~Window(); void MoveWindow(short newx, newy); } Window::Window() { if (necessary-libs-not-open) open_the_necessary_libs; xpos = ypos = 0; name = "Default Window" ; xwid = ywid = 50; } Window::Window(char *s) { xpos = ypos = 0; name = new char [strlen(s)+1]; strcpy(name, s); xwid = ywid = 50; } Window::~Window() { delete name; if (I am the last Window) close_the_libraries_and_release_the_memory; } … main() { Window a; } Simply declaring variable a to be of type Window causes the compiler to do everything you specified in your "constructor." In this case, two different constructors were defined, one for default windows, one for named windows. The compiler sees "Window a" and uses the default constructor. If you had written "Window a("Showing Off")" you'd get the named constructor. Once the variable passes out of scope, the compiler calls all the cleanup code in your "destructor," named by convention as ~<class being destroyed>. In complex environments such as Intuition where there's a lot of preliminary and a lot of cleanup, this is a keystroke-saver. By the way, there are at least a half dozen bugs in the example code, but you get the idea.
#88477From: Dave LoveFeb 3, 1990 10:33 PM
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 ]
#88482From: Dave LoveFeb 3, 1990 10:35 PM
[ continuation ] 4. Derived classes and virtual functions C++ allows you to define new classes based upon other classes (very similar to wrapping structures around other structures (like MsgPort and Node)). The new "derived" class inherits all the properities of the base class. Further, if the base class contains functions declared as "virtual", the derived class can override them, if it needs to. Consider the following example: class object { // These two slashes denote a C++ comment protected: // The following elements are for internal use only object* next; public: // Anyone can access the following elements int x_pos, y_pos; char* name; object(char* name = NULL, int x = 0, int y = 0); // Constructor ~object(); // destructor virtual void draw(); // This function can be overridden by derived classes virtual void move(); void fill(); } Note that C++ allows functions to have default values, so the constructor above could legally be called with zero, one, two or three parameters. Now I could define a few specific objects as follows: class square : public object { // square is "derived" from the base class object int width; square(int width = 1); ~square(); void draw(); // and square will have its own draw routine void move(); } class circle : public object { // just another object int diameter; circle(int diameter = 0); ~circle(); void draw(); void move(); } Now, suppose you have a linked-list of objects (or classes derived from objects) and you want to draw them. The following code will do it: for (object* o = list; o; o = o->next) o->draw(); Circles would call the draw routine defined in the circle class, while squares call the draw routine defined in the square class. Also, notice that C++ allows you to declare variables where they make sense: the object pointer o is declared in the for() statement and is only defined within that statement. Well, now that you understand all that… 🙂 Actually I'll be happy if only a portion of it makes sense. C++ is a very powerful language, and I've only
#88606From: Steve AhlstromFeb 4, 1990 9:40 PM
Dave, Thanks! I've save the msgs and will try to figure it all out when I've got a bit of time! -sja