#include <iostream>
#include <string>
#include <sstream>
#include "game.h"
#include "board.h"
#include "piece.h"
using namespace std;
Run Code Online (Sandbox Code Playgroud)
#ifndef GAME_H
#define GAME_H
#include <string>
class Game
{
private:
string white;
string black;
string title;
public:
Game(istream&, ostream&);
void display(colour, short);
};
#endif
Run Code Online (Sandbox Code Playgroud)
错误是:
game.h:8 error: 'string' does not name a type
game.h:9 error: 'string' does not name a type
Mic*_*zek 94
您的using声明在game.cpp,而不是game.h您实际声明字符串变量的位置.您打算在using namespace std;使用的行上方放入标题,string这将使这些行找到命名空间中string定义的类型std.
正如其他人所指出的那样,这不是标题中的好习惯 - 包含该标题的每个人也会不由自主地命中using并导入std其命名空间; 正确的解决办法是改变那些线使用std::string,而不是
Joh*_*web 37
string没有命名类型.string调用标题中的类std::string.
请不要放入using namespace std头文件,它会污染该头的所有用户的全局命名空间.另请参阅"为什么'使用命名空间std;' 在C++中被认为是一种不好的做法?"
你的课应该是这样的:
#include <string>
class Game
{
private:
std::string white;
std::string black;
std::string title;
public:
Game(std::istream&, std::ostream&);
void display(colour, short);
};
Run Code Online (Sandbox Code Playgroud)
只需在头文件中使用std::限定符即可string.
事实上,你应该使用它,istream并且ostream- 然后你需要#include <iostream>在头文件的顶部使它更自包含.
尝试using namespace std;在顶部game.h或使用完全限定std::string而不是string.
的namespace在game.cpp是被包括在报头之后.
| 归档时间: |
|
| 查看次数: |
217920 次 |
| 最近记录: |