I'm trying to make a data structure which contains all the monsters in the game. For some reason when I allocate new monster i get "cannot convert Monster** to p_monster {Aka monster*} in initialization. If you could help me out it would be much appreciated. Thanks in advance
struct Monster {
int x;
int y;
int health;
Monster *next;
};
typedef Monster* p_monster;
class gameUtils {
protected:
p_monster monster};
public:
gameUtils(){
monster=NULL;
...}
function(){
monster = getMonster(monster)} // so that I can assign whatever value I want to monster->last->next through the function itself
p_monster getMonster(p_monster monster){
p_monster newMonster = new p_monster;
if(monster==NULL){
monster=newMonster;
}else{
.... // find last monster then create new one and pass it to caller
return monster; // returns new monster without any value
}
std::list<Monster>. Thestd::listhas already been tested and works, so that you can move on and do other coding.p_monster newMonster = new p_monster;should bep_monster newMonster = new Monster;I think you confused yourself with the unnecessary typedefp_monster {Aka monster*}- that you are compelled to mention that is an indication of what a terrible idea hiding pointer types in typedef aliases really is. And if you don't think so, look at @drescherjm ' s comment above. I suspect he's hyper-accurate in that assessment.