gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

C/C++ > problem with inheritance

#32450 - Jau - Thu Dec 23, 2004 12:54 am

What is wrong here?

Code:

#include "mygba.h"

#ifndef _ENEMIC_H_
#define _ENEMIC_H_

class Enemic: public Personatge {
    public:
    s32 x, y;
    s32 vx, vy;
    s32 ax, ay;
    u8 tocaTerra;
    u8 colisioDreta;
    u8 colisioEsq;

    Enemic();
    ~Enemic();
};

#endif


The complier gives me the following error message

In file included from enemic.cpp:1:
enemic.h:7: error: parse error before `{' token

I have another file where there is another class that inherits from Personatge and it doesn't give me any error. Why? Can't I have two derived classes from the same class?

#32452 - DekuTree64 - Thu Dec 23, 2004 1:05 am

Looks like you're missing an #include "Persontage.h", since the class isn't defined anywhere.
Maybe what's happening in your other file is that the.cpp file just happens to include Persontage before the other class that inherits from it, so it doesn't cause any trouble.

Do be careful when including headers in other headers though, it can get messy if you have a whole lot of them all dependent on eachother.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#32454 - Jau - Thu Dec 23, 2004 1:16 am

Thanks, it helped me.