Jump to content

HELP!!! time is running out

- - - - -

  • Please log in to reply
1 reply to this topic

#1
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
wats wrong with this?

I am writing a cheap ass game that will be played over LAN and hopefully work over the internet. Im having trouble, i cant go through the list and return each items value..im using qt and i am inheriting from class QList as i want each player in the game to have a list of all other players and there attributes,
I want to return items in the following way but its not working:

following is class header:
/* Player is the base class for two class named Player_Evil and Player_Good */

class PlayerList : public QList< Player >{
//class body here
}

following function to return a Player object using IP that is not working

Player* PlayerList::getPlayerInfo( QString ip )const{

foreach( Player p, this ){

if( p.tostringIP( ) == ip ) return &p;

}

return 0; //if not found

}

I get an error when i include this function code I dont know why, I suspect that it might be the 'this' pointer in the foreach loop, I thought i could do that seeing as I am inheriting QList, I have been able to use all of QList's functions with the 'this' pointer...if more code is needed to help solve this please ask

#2
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
Hello, for those of you that are interested to know i found what the problem was in the program. It was the header of the foreach loop. the 'this' pointer is being used wrong:

it is supposed to be '*this' that the value of the current object.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users