Friday, August 22, 2008

Why I like c++??

c++ is a general purpose programming language. This every body knows.. let me show you a neat construct for looping through group of same objects..

Just write this macro.. somewhere in the header file..

#define forAll(iList, list) for(int i=0; i<>

For handling group of objects list<> and vector<> classes from STL (Standered template library) are very useful and in the above macro I assume the 'list' macro parameter is either a list<>, vector<> or any other object with .size() function which returns size in integers..

Now let us assume you a class with name Garbage is there and you want to handle group of those objects for some nonsense purpose... Now you can write a very neat code which looks like this..

vector<> Garbages;
/*
do all operations like adding and deleting.. individual Garbage object..
*/

forAll (iGarbage, Garbages) {
Garbages[iGarbage] = something...
}

looks neat no....
Post a Comment