I have a program which outputs the following in the compiler console after a failed build:
1>------ Build started: Project: BlackjackAttack, Configuration: Debug Win32 ------
1>Build started 9/18/2012 10:59:28 PM.
1>InitializeBuildStatus:
1> Touching "Debug\BlackjackAttack.unsuccessfulbuild".
1>ClCompile:
1> main.cpp
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\bja\blackjackattack\config.h(5): error C2146: syntax error : missing ';' before identifier 'GAME_NAME'
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> Display.cpp
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\bja\blackjackattack\config.h(5): error C2146: syntax error : missing ';' before identifier 'GAME_NAME'
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1> Config.cpp
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\bja\blackjackattack\config.h(5): error C2146: syntax error : missing ';' before identifier 'GAME_NAME'
1>c:\bja\blackjackattack\config.h(5): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\bja\blackjackattack\config.cpp(7): error C2039: 'GAME_NAME' : is not a member of 'Config'
1> c:\bja\blackjackattack\config.h(1) : see declaration of 'Config'
1> Generating Code...
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:01.32
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Config.h:
class Config {
public:
static const int DEFAULT_CONSOLE_COLOR = 7;
static const string GAME_NAME;
};
Config.cpp:
#include <string>
#include "Config.h"
using std::string;
const string Config::GAME_NAME = "Name";
main.cpp:
#include <iostream>
#include "Config.h"
#include "Display.h"
int main(int argc, char *argv[]) {
return 0;
}
Could someone please explain why my program is outputting the above-mentioned errors?
Thank you for your time.
This is caused by the way that you are including the Config.h file through out your project.
Since your Config class references std::string you must include std::string before you declare the class.
In your Config.cpp file you’ve resolved the conflict however you haven’t done the same in your main.cpp file.
You have two options to fix your problem.
Every time you include “Config.h” you include string.h and write the “using std::string” on the lines immediately above it.
You include string.h at the top of your Config.h file along with the “using std::string;” directive.