呃,一天 2 个问题。我正在经历你经常听到的那些糟糕的日子之一。我一直在组织我的小项目,让它不那么困惑。它处于开发的开始阶段,因此没有太多进展。我在下面有这个标题
#pragma once
#include <string>
class Game_Map
{
private:
int map_width;
int map_height;
string map_data [50][50]
public:
Game_Map(int default_width = 20,int default_height = 20)
~Game_Map()
};
现在看来,应该没有问题了。我避免使用“使用”,并且我将编程保持到现在的基本状态以防止外部干扰。但是我是否有 100% 的时间收到“map.h:9:9: error: 'string' does not name a type”
我确定我错过了什么。谁能看出我哪里出错了?
最佳答案
改变
string map_data [50][50]
到
std::string map_data [50][50];
这是必要的,因为字符串属于 std 命名空间。
不要在头文件中使用“using”声明或指令。
关于C++ 'string' 未在 header 中命名类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23017878/