C++类和指针(我再次使用Tile类:D)
C++ classes and pointers (Me again with my Tile classes :D)
链接到我的最后一个主题: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,因为我不知道它是什么。可能是一个枚举。除此之外,你对分号还有很多问题。
相关文章:
- 1d 智能指针不适用于语法 (*)++
- 在C#中处理C++指针而不使用unsafe的最佳方法
- 为什么使用 "this" 指针调用派生成员函数?
- 函数向量_指针有不同的原型,我可以构建一个吗
- 使用指针从C++中的数组中获取最大值
- 助记符和指向成员语法的指针
- 嵌入方指针压缩已禁用
- 数组的指针从不分段故障
- C++ 指针的内存地址和指向数组的内存地址如何相同?
- 何时在引用或唯一指针上使用移动语义
- QMetaObject invokeMethod的基于函数指针的语法
- 如何从 std::atomic 中提取指针 T<T>?
- 如何在 C# 中映射双 C 结构指针?
- C++将浮点指针值舍入为小数位数
- 为什么++(*p)更改指针值
- 调整大小后指向元素值的指针unordered_map有效?
- 正在将指针转换为范围
- 使用指向成员的指针将成员函数作为参数传递
- 将OpenCV C++重写为EmguCV C#-如何使用指针
- C++类和指针(我再次使用Tile类:D)