I've been trying to make a program, using classes and vectors, and I keep running into this error, or I guess, errors.
"Severity Code Description Project File Line Suppression State
Error LNK2005 "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > filePath" (?filePath@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Source.obj FinalProjectEver C:\Users\Bruno***\source\repos\FinalProjectEver\FinalProjectEver\Voter.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2005 "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > nameOfFile" (?nameOfFile@@3V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@A) already defined in Source.obj FinalProjectEver C:\Users\Brunk53350\source\repos\FinalProjectEver\FinalProjectEver\Voter.obj 1
Severity Code Description Project File Line Suppression State
Error LNK2005 "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl FileLoader(void)" (?FileLoader@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ) already defined in Source.obj FinalProjectEver C:\Users\Brunk53350\source\repos\FinalProjectEver\FinalProjectEver\Voter.obj 1"
basically its just twenty of those. This is an error I've ran into in MULTIPLE programs I've had. Here are some bits of my code for reference
My header
1 2 3 4 5 6 7 8 9 10
|
class Voter {
private:
string firstName;
string lastName;
string state;
int zipCode;
string party;
public:
void setVoter(string, string, string, int, string);
void printVoter();
|
How I have it called:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
#include "Voter.h"
void Voter::setVoter(string first, string last, string staet, int zip, string partia) {
firstName = first;
lastName = last;
state = staet;
zipCode = zip;
party = partia;
}
void Voter::printVoter() {
cout << "Voter first name: " << firstName << endl;
cout << "Voter last name: " << lastName << endl;
cout << "Voters state: " << state << endl;
cout << "Voters zip-code: " << zipCode << endl;
cout << "Voters registered party: " << party << endl;
}
|
bits from how its called in my main program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
vector<Voter>votersVect(1, voterAdder());
while (yesNo == 'y') {
int choice = menu();
switch (choice) {
case 1:
votersVect.push_back(voterAdder());
totalVoters++;
cout << "Votes: " << totalVoters << endl;
break;
case 2:
for (int i = 0; i < totalVoters; i++)
{
votersVect[i].printVoter();
}
break;
|