Jump to content

Recommended Posts

Posted

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

Posted

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);

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...