When I try to compile this code, I get:
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'
part of my code:
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;}; };
I really don’t know what to do, I was looking for a solution, but I couldn’t find anything similar to my problem ... Actually, I have more classes with a parent “tile”, and that was fine before ... Thanx for any help.
EDIT:
I decided to change all return types to pointers to avoid memory leaks, but now I got:
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"
It is unique in the base class, everything else is in order ... Each function of the tile class that returns * tile has this error ...
Some codes:
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() {}; };
c ++ class forward-declaration
noisy cat
source share