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

C++ classes and pointers (Me again with my Tile classes :D)

本文关键字:Tile 指针 C++      更新时间:2023-10-16

链接到我的最后一个主题:C++类正向声明

现在主要的事情:

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

27 C:Dev-CppProjektyyystrategyTiles.h ISO C++ forbids declaration of `tile' with no type 
27 C:Dev-CppProjektyyystrategyTiles.h expected `;' before "tick"

它只在基类中,其他一切都好…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() {};
};

在声明指针时,tick的返回中缺少一个分号,而*在类型后面:

tile* tick() {return this;};
class tile
{
      public:
          double health;
          tile* takeDamage(int ammount) {return this;}
          tile* onDestroy() {return this;}
          tile* onUse() {return this;}
          tile* tick() {return this;}
          virtual void onCreate() {}
};

给你。我删除了tile_type,因为我不知道它是什么。可能是一个枚举。除此之外,你对分号还有很多问题。