DarthRaff Posted January 8, 2015 Share Posted January 8, 2015 Hello, trying some simple collision but have problem when i try to use a class functions inside another class. This are the pieces of code : .h : #include "elementograf.h" #include "nivel.h" class Prota : public ElementoGraf { public: Prota(); void moverDerecha(Nivel n); void moverIzquierda(Nivel n); . . . } .cpp: #include "elementograf.h" #include "prota.h" #include "nivel.h" void Prota::moverDerecha(Nivel n) { if (n.esPosibleMover(posX+4, posY, posX+anchura+4, posY+altura)) { posX += 4; } } void Prota::moverIzquierda(Nivel) { if (n.esPosibleMover(posX+4, posY, posX+anchura+4, posY+altura)) { posX -= 4; } } in main : void comprobarTeclas() { if(hard.comprobarTecla(TECLA_ESC)) { partidaTerminada = true; } if(hard.comprobarTecla(TECLA_DER)) { prota->moverDerecha(Nivel n); // error: expected primary-expression before "n" } if(hard.comprobarTecla(TECLA_IZQ)) { prota->moverIzquierda(Nivel n);// error: expected primary-expression before "n" } } Don't know what am i missing, can someone help me, please ? Thankyou Quote Link to comment Share on other sites More sharing options...
Rick Posted January 8, 2015 Share Posted January 8, 2015 When you call the function you pass your object to it. You are defining an object with Nivel n inside the parameter. I've never done that before and guessing it's not liking that. Try: Nivel n; prota->moverDerecha(n); Quote Link to comment Share on other sites More sharing options...
DarthRaff Posted January 8, 2015 Author Share Posted January 8, 2015 Yes, no error, thank you very much Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.