C++ does not support default-int
C++ does not support default-int
我的私有变量Player_Player出现错误;和Level _ Level;它告诉我它缺少类型说明符,我不确定为什么。我已经为Level和Player创建了类,所以我不应该使用Player和Level来指定变量类型吗?
谢谢你的帮助,
mike
//GameSystem.h
#pragma once
#include "Player.h"
#include "Level.h"
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <vector>
using namespace std;
class GameSystem
{
public:
GameSystem(string levelFileName);
void playGame();
private:
Level _level;
Player _player;
};
#//Player.h
#pragma once
#include "GameSystem.h"
#include "Level.h"
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <vector>
using namespace std;
class Player
{
public:
Player();
void initPlayer(int level, int health, int attack, int defense, int experience);
//Setters
void setPosition(int x, int y);
//Getters
void getPosition(int &x, int &y);
private:
//Properties
int _level;
int _health;
int _attack;
int _defense;
int _experience;
//Position
int _x;
int _y;
};
您的GameSystem.h
文件具有以下行:
#include "Player.h"
您的Player.h
文件具有以下行:
#include "GameSystem.h"
这不太好。此外,头文件中的Player
类声明不使用GameSystem.h
中的任何内容,因此从头文件中删除GameSystem.h
(我建议删除Player.h头文件中没有解析任何内容的所有#include
)。
编辑1:
我更改了头文件,并使它们使用Include Guards。我没有任何错误
Player.hpp:
#ifndef PLAYER_HPP
#define PLAYER_HPP
class Player
{
public:
Player();
void initPlayer(int level, int health, int attack, int defense, int experience);
//Setters
void setPosition(int x, int y);
//Getters
void getPosition(int &x, int &y);
private:
//Properties
int _level;
int _health;
int _attack;
int _defense;
int _experience;
//Position
int _x;
int _y;
};
#endif // PLAYER_HPP
GameSystem.hpp:
#ifndef GSYSTEM_HPP
#define GSYSTEM_HPP
#include "Player.hpp"
#include "Level.hpp"
#include <string>
using namespace std;
class GameSystem
{
public:
GameSystem(string levelFileName);
void playGame();
private:
Level _level;
Player _player;
};
#endif // GSYSTEM_HPP
我更改了文件扩展名,以帮助区分C语言头文件(.h)和C++语言头文件
我还通过删除未使用的包含文件简化了头文件。
这里有一个依赖性问题,有两种解决方案。
首先,Player.h实际上并不依赖于GameSystem.h,所以不要将GameSystem.h包含在Player.h 中
//Player.h
#pragma once
//Remove GameSystem.h
//#include "GameSystem.h"
#include "Level.h"
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <vector>
如果出于某种原因,您确实需要在Player类中声明GameSystem类,请执行以下操作:
//Player.h
#pragma once
#include "Level.h"
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <conio.h>
#include <vector>
//Declare the class
class GameSystem;
您需要在.cpp文件中包含完整的头文件,但实际上并不需要完整的类定义来在另一个类定义中使用一个类(实际上,GameSystem.h甚至不需要包含Player.h,它可以只声明但不定义Player类)
相关文章:
- 在提升multi_index容器中,是否定义了"default index"?
- 为什么在全局范围内使用"extern int a"似乎不行?
- int(c) 和 c-'0' 之间的区别。C++
- 从"int*"强制转换为"unsigned int"会丢失精度错误
- 为什么野牛仍在使用"int yylex(void)",却找不到"int yylex(YYS
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 请解释这句话(cout<<1+int((a<b)^((b-a)&1) )<<endl
- 是否可以从int转换为enum类类型
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 向量 <int> a {N, 0} 和 int arr a[N] = {0} 的时间复杂度有什么区别
- 由于"error C4430: missing type specifier - int assumed. Note: C++ does not support default-int",我现在无法编
- 缺少类型说明符 - 假定为 int.注意 c++ 不支持 default-int
- 错误:C4430:缺少类型说明符-假定为int.注意:C++不支持default-int
- c++default-int中的语法错误
- C++ does not support default-int
- VisualStudio 2010 Express-C++上的RDTSC不支持default-int
- VC++缺少类型说明符-假定为int.注意:C++不支持default-int
- C2143 缺少 '*' 之前的';' 和 C 4430 缺少类型说明符 - 假定为 int。注意 C++ 不支持 default-int
- 错误c4430缺少类型说明符-假定为int.注意:c++不支持default-int生成器
- c++ int switch语句总是指向' default '