I'm currently writing some code to read a .ini file and set variables according to its contents. I've decided to wrap this in a very simple class. The class is declared in IniParser.h:
IniParser::Parse is implemented in IniParser.cpp (code is probably crappy and/or buggy, so I've commented it out for now):Code:#ifndef INIPARSER_H #define INIPARSER_H class IniParser { public: void Parse(char *fileName); }; #endif // INIPARSER_H
I'm unsure how/where I should include the header file now. If I include it from the main file like this:Code:void IniParser::Parse(char *fileName) { /* ifstream iniFile (*fileName); if(!iniFile.is_open()) { std::cout << "Could not open ini file: " << *fileName << std::endl; return 0; // Probably bad since return type is void.. } char inputStr[128]; int inputInt; float inputFloat; while(iniFile >> inputStr) { switch (*inputStr) { case "testVar": iniFile >> inputFloat; // Is this possible? std::cout << "testVar = " << inputFloat << std::endl; //TODO: Set the variable testVar to the content of inputFloat break; default: std::cout << "Unknown variable encountered while reading"<< *fileName << std::endl; break; } }*/ }
I get "iniparser.cpp(5) : error C2653: 'IniParser' : is not a class or namespace name"Code:#include "IniParser.h" #include "IniParser.cpp"
If I include the header inside the IniParser.cpp I get "error LNK2005: "public: void __thiscall IniParser::Parse(char *)" (?Parse@IniParser@@QAEXPAD@Z) already defined in Shard Server.obj" - where Shard Server.obj is the main file.
What is the 'right' way to use header files?



LinkBack URL
About LinkBacks



CornedBee