#include <iostream> #include <string> #include <sstream> #include "game.h" #include "board.h" #include "piece.h" using namespace std;
#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
The error is:
game.h:8 error: 'string' does not name a type
game.h:9 error: 'string' does not name a type
You're missing your main. The code is outside of a function and is considered by the compiler to be either a declaration of variables, class, structs or other such commands.
In C++, you should use the string header. Write #include <string> at the top of your file. When you declare a variable, the type is string , and it's in the std namespace, so its full name is std::string .
Your using
declaration is in game.cpp
, not game.h
where you actually declare string variables. You intended to put using namespace std;
into the header, above the lines that use string
, which would let those lines find the string
type defined in the std
namespace.
As others have pointed out, this is not good practice in headers -- everyone who includes that header will also involuntarily hit the using
line and import std
into their namespace; the right solution is to change those lines to use std::string
instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With