I was trying to make a little program that parses files into variable/value pairs and stores them in a map. The compiler (Visual C++ Express Edition) is returning these linker errors, and I have no idea what is wrong:
1>Parse.obj : error LNK2005: "class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > * __cdecl ParseFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ParseFile@@YAPAV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in main.obj
1>Parse.obj : error LNK2005: "class std::map<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > >,class std::allocator<struct std::pair<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const ,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > > * __cdecl ParseFile(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?ParseFile@@$$FYAPAV?$map@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@V?$allocator@U?$pair@$$CBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@2@@Z) already defined in main.obj
1>C:\Documents and Settings\sotsilent\Desktop\Test Programming\Parser\Debug\Parser.exe : fatal error LNK1169: one or more multiply defined symbols found
Here's the code:
//Parse.cpp - Implementation
//Sheldon Bachstein
//December 30, 2007
//Using ifstreams
#include<fstream>
using std::ifstream;
//Using strings and maps
#include<string>
#include<map>
using std::map;
using std::string;
map<string, string>* ParseFile(string file)
{
ifstream f(file.c_str()); //Open file for input.
if(!f) //If not ready to read...
return NULL; // return null.
map<string, string> *result = new map<string, string>;
char c;
string token;
string first;
bool isFirst = true;
bool quotes = false;
while(f.good())
{
f.get(c); //Get next char
switch(c)
{
case ' ':
if(quotes)
token += c; //If inside quotes, keep spaces
break;
case '=':
if(!isFirst)
return NULL; //This shouldn't happen
first = token;
token.clear();
isFirst = false;
break;
case '\"':
if(quotes)
quotes = false;
else
quotes = true;
break;
case '\n':
if(isFirst)
return NULL; //Newlines should only be found after values.
//*result[first] = token;
result->insert(std::make_pair(first, token));
token.clear();
first.clear();
break;
case '[':
f.ignore(255, '\n');
break;
default:
token += c;
break;
}
}
return result; //Return result.
}
Can anyone please explain what's wrong? I have absolutely no idea. Any help is appreciated a lot.