C未声明的标识符

weixin_38067693 2019-09-12 01:01:28
我想创造一个海战游戏.我有两个班:船和细胞. #pragma once #include"stdafx.h" #include"Globals.h" #include<vector> #include"MCell.h" class Ship { private: int lenght; int oriantation; vector<Cell*> cells; vector<Cell*> aroundCells; … #pragma once #include<vector> #include"MShip.h" class Cell { private: bool haveShip; bool selected; bool around; int x; int y; Ship* ship; 我有很多错误: 1>projects\seewar\seewar\mship.h(13): error C2065: 'Cell' : undeclared identifier 1>projects\seewar\seewar\mship.h(13): error C2059: syntax error : '>' 1>projects\seewar\seewar\mship.h(14): error C2065: 'Cell' : undeclared identifier 代码有什么问题?
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
weixin_38080744 2019-09-12
  • 打赏
  • 举报
回复
那么你的问题在于,当你包含MCell.h时,你包括MShip.h,它引用了MCell.h中定义的Cell.但是,MShip.h指的是MCell.h,由于pragma曾经不会包含在内.如果pragma曾经不在那里那么你会得到一个无限循环,它会堆积溢出你的编译器…… 相反,你可以使用前向声明. 即从MShip.h中删除#include“MCell.h”并将其替换为“class Cell”.所有循环引用问题都将消失:)

476

社区成员

发帖
与我相关
我的任务
社区描述
其他技术讨论专区
其他 技术论坛(原bbs)
社区管理员
  • 其他技术讨论专区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧