Bmax code style

BlitzMax Forums/BlitzMax Beginners Area/Bmax code style

Hi, I'm trying to write some C++ code from an example peice of code from this forum but I'm stuck, can someone tell me what this is doing?
Local array:Int[10]

For a:int = 0 to 10
     Local type:TType = TType( array[a] )
Next



I can't figure out what the type:TType is doing, what is it doing here TType(array[a]) ?? in C++ that would be a constructor!

Thanks.

Must be one of the worst examples you can find :-)

You'll get an ArrayOutOfBounds with that loop for starters...
"type" is not a valid variable name.
TType() looks like a cast, but it is also defined as a Type. It might be a function too, but I'm not sure you can do that.
Certainly you won't be able to cast from int to a type, with much success!

HAHA Yeah I know of the code errors.

Ah, so it could be a cast of somekind?
It's just so bloody vague?!

... but isn't it vague due to poor variable names and dodgy coding? Where did you get the example from?

Yep the code example was too vague for an answer, it's basically from what I can tell a c++ type_cast to loop though inherited/derived types in a list to find the Type you want, so in Bmax you do this, roughly:
For local ent:Entity = EachIn entity_list
     Local player:Player = Player(ent)  ' Player is derived from Entity
     '  Do some player code
Next

and my conversion in C++
list<Entity*>::iterator iter;

for(iter = entity_list->begin(); iter != entity_list->end(); iter++)
{
      Player* player = dynamic_cast<Player*>(*iter);
      // Do some player code
}


But you can more succinctly just write,

for local ent:Player = EachIn entity_list
'do stuff
next


even if entity_list contains objects that are not of type "player".