D&C Lug - Home Page
Devon & Cornwall Linux Users' Group

[ Date Index ][ Thread Index ]
[ <= Previous by date / thread ] [ Next by date / thread => ]

Re: [LUG] GCC compilation?



Neil Williams wrote:

So what was the point of writing it in Java??!!

Having written a non-portable Java program... Our motivation was
to allow easier portability in the future, at the time Java's
printing facilities left us cold, so we cheated in the printing
class. Fitting alternative printing solutions will be easy when
the time comes.

Not sure about Nokia's motivation. JBuilder was not 100% Java
when it started life, but they were able to make it portable
later. I think bits were in Delphi originally.

I've seen otherwise quite "good" programmers implement their own
linked links in C++ through ignorance of the STL - arghhhhhhhh

Please explain Simon - is STL akin to the API in Windoze speak?

STL is the standard template library. Templates let you apply
common algorithmns and techniques in C++. My problem was not his
not using the STL, it isn't perfect(!), but that you need a
reason not to, otherwise your just reinventing the wheel.

Here is an utterly trivial snippet I wrote whilst reading BS C++
Programming language chapter on STL.

Basically create a structure "node", and then create a "list"
called "top" of that structure, and then play with it a bit.
Nothing in the example requires the "list" template, and you can
probably swap 'list' for another similar template.

Hopefully you've been using them without knowing it?

I make no guarantees on the quality of the example, it is part
BS, part mediocre programmer trying to grasp the concepts whilst
mastering the syntax.

.....list.cpp
#include <iostream.h>
#include <list>

struct node {
char c;
int i;
double d;
// basic constructor
node () {}
// syntax c(c) etc presumably handles trivial assignments.
node (char c, int i, double d) : c(c), i(i), d(d) {}
};

int main() {
list<node> top;

for (int i=0; i<10; i++){
node n('a'+i, i, i+0.5);
top.push_back(n);
} //end for      

list<node>::iterator ni; 
for (ni=top.begin() ; ni != top.end() ; ni++){
cout <<"C: "<<(*ni).c<<" I: "<<(*ni).i<<" D: "<<(*ni).d<<endl;
} //end for

cout <<endl<<"Now backwards?"<<endl;

for (ni=--top.end(); ni != --top.begin(); ni--){
cout <<"C: "<<(*ni).c<<" I: "<<(*ni).i<<" D: "<<(*ni).d<<endl;
}

cout <<endl<<" Now erase list from beginning "<<endl<<endl;

while ( 0<top.size() ) {

node n = top.front() ;
top.erase(top.begin());

cout <<"Erased "<<n.c<<endl;
} // end while

} // end main

--
The Mailing List for the Devon & Cornwall LUG
Mail majordomo@xxxxxxxxxxxx with "unsubscribe list" in the
message body to unsubscribe.


Lynx friendly