使用了未定义的类_解决方法
来源:互联网 发布:淘宝老顾客回购率 编辑:程序博客网 时间:2024/05/20 06:51
在游戏类的编写中,遇到了一个导入工程后运行出现”使用了未定义的类“的错误。
绞尽脑汁也没搞懂是哪里出现了问题,看了其他人的blog后才发现了问题所在:类定义的顺序
第一次错误代码如下:
class Hp : public res{private:int hpValue;//the value of hp this kind of medicine can provide;int number;//the number of the kind of medicine that people has;public:Hp(){}void setHpValue(int value){hpValue = value;}Hp(int value, string _name){ type = 1;//define the type is hp;hpValue = value;//define the value of hp provided;name = _name;//define the name of the medicine;number = 0;//define the number of the medicine(initialized);}int getType(){return type;//get the type of the medicine;}void used(Person &person){
person.addHp();
}void sub(int _number){number -= _number; //subcline number medicines;}void add(int _number){number += _number; //add the number medicines;}int getNumber(){return number; //return the number of the medicine;}void setNumber(int value){number = value;//set the number of the medicine;}};
class Person{a function with Hp parament;};
有代码可以看出来,在hp类中使用到了person类,而在person类中也使用到了hp类,所以出现的定义问题。但是要怎么解决呢?
第一次修改,知道了类定义可以先声明的说法后,在第一排添加了 class Person;
可是,还是失败,于是乎,看见了某大佬的blog,发现原来在类中只要涉及到还没有实现的类的函数,也要先声明,然后在类的最后实现,于是,最后改为
class Person;class Hp : public res{private:int hpValue;//the value of hp this kind of medicine can provide;int number;//the number of the kind of medicine that people has;public:Hp(){}void setHpValue(int value){hpValue = value;}Hp(int value, string _name){ type = 1;//define the type is hp;hpValue = value;//define the value of hp provided;name = _name;//define the name of the medicine;number = 0;//define the number of the medicine(initialized);}int getType(){return type;//get the type of the medicine;}void used(Person &person);void sub(int _number){number -= _number; //subcline number medicines;}void add(int _number){number += _number; //add the number medicines;}int getNumber(){return number; //return the number of the medicine;}void setNumber(int value){number = value;//set the number of the medicine;}};class Person{};void Hp::used(Person &person){person.addHp(hpValue); //add the hp of the person;sub(1);//the number of the medicine subcline 1;}于是乎,成功了!
阅读全文
0 0
- 使用了未定义的类_解决方法
- PageMethods未定义的解决方法
- C++ error C2027:使用了未定义类型 类的调用顺序
- C++ error C2027:使用了未定义类型 类的调用顺序
- C++ error C2027:使用了未定义类型 类的调用顺序
- AnimateWindow()函数未定义的解决方法
- 问题setday未定义的解决方法
- 使用未定义的 class
- 关于 ‘AjaxControlToolKit ’未定义 和 ‘Sys’未定义 的解决方法
- cuda使用原子操作出现未定义解决方法
- Ajax中“Sys未定义”错误的解决方法
- ASP.NET AJAX Sys未定义的解决方法
- MapXtreme中mapinfowebtoolactivate 未定义问题的解决方法!
- JS调用WebService提示"未定义"的解决方法
- 【'DWREngine' 或'DWRUtil' 未定义】错误的解决方法:
- EM 出现oracle unqname未定义的解决方法
- ie9 提示'console' 未定义问题的解决方法
- IE10、IE11出现“_doPostBack未定义”的解决方法
- LeetCode 69. Sqrt(x)
- Apriori的Python实现
- java基础入门学习
- Eclipse创建Maven项目报错的解决
- IRP结构
- 使用了未定义的类_解决方法
- 最全原生AJAX请求步骤
- 在父页面处理用户控件的事件
- hive------join语法介绍
- Spring多数据源管理
- JDE 变量的命名!
- 事无贵贱,IT人不可自己瞧不起自己
- scikit-learn数据预处理fit_transform()与transform()的区别
- tomcat 远程部署