Cuando intento compilar el código me sale:clase de C++ declaración adelantada
52 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h invalid use of undefined type `struct tile_tree_apple'
46 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h forward declaration of `struct tile_tree_apple'
alguna parte de mi código:
class tile_tree_apple;
class tile_tree : public tile
{
public:
tile onDestroy() {return *new tile_grass;};
tile tick() {if (rand()%20==0) return *new tile_tree_apple;};
void onCreate() {health=rand()%5+4; type=TILET_TREE;};
};
class tile_tree_apple : public tile
{
public:
tile onDestroy() {return *new tile_grass;};
tile tick() {if (rand()%20==0) return *new tile_tree;};
void onCreate() {health=rand()%5+4; type=TILET_TREE_APPLE;};
tile onUse() {return *new tile_tree;};
};
Realmente no sabía qué hacer, busqué la solución pero no pude encontrar nada similar a mi problema ... En realidad, tengo más clases con "azulejo" parental y estaba bien antes ... Gracias por cualquier ayuda.
EDIT:
decidí cambiar todos los tipos devueltos a los punteros para evitar pérdidas de memoria, pero ahora tengo:
27 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h ISO C++ forbids declaration of `tile' with no type
27 C:\Dev-Cpp\Projektyyy\strategy\Tiles.h expected `;' before "tick"
Su único en la clase base, todo lo demás está bien ... Cada función de la clase de azulejos que devuelven * baldosas tiene este error ...
Algunos código:
class tile
{
public:
double health;
tile_type type;
*tile takeDamage(int ammount) {return this;};
*tile onDestroy() {return this;};
*tile onUse() {return this;};
*tile tick() {return this};
virtual void onCreate() {};
};
¿El 'inline' también tiene que ir en la definición de la clase? Nunca estoy demasiado seguro de esto ... –
@KerrekSB: AFAIR, debe ir a la declaración o a la definición, pero no importa cuál –
@KerrekSB: debe ir solo en la definición; ponerlo en la declaración no tiene ningún efecto en absoluto. – ildjarn