C++类和指针(我再次使用我的Tile类:D)

noi*_*cat 0 c++ class

链接到我的上一个主题: C++类前向声明

现在主要的事情:

我决定将所有返回的类型更改为指针以避免内存泄漏,但现在我得到了:

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"
Run Code Online (Sandbox Code Playgroud)

它只在基类中,其他一切都没问题... tile类中返回*tile的每个函数都有这个错误...

一些代码:

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() {};
};
Run Code Online (Sandbox Code Playgroud)

woc*_*esa 5

你在返回时缺少一个分号tick,并*在声明指针时在类型之后:

tile* tick() {return this;};
Run Code Online (Sandbox Code Playgroud)