I have a total of three classes...
1. Source.cpp (Where the main function is.)
2. Variables.h (Where I declared all my variables in, Variables.cpp is pretty much irrelevant)
3. Functions.cpp & .h (Where I make the functions to run in the main function in Source.cpp)
In main i have this
#include <iostream>
#include <cstdlib>
#include "Variables.h"
#include "Functions.h"
#include <ctime>
using namespace std;
Variables vari;
Functions func;
int main(){
cout << "\n\n>>> ";
cin >> vari.answer;
func.choiceChecker();
}
In Functions.cpp I have this
Variables vari;
void Functions::choiceChecker(){
if (vari.answer == 1){
scenario1();
}
else{
cout << "Failed";
}
}
I always get the output failed, instead of running the scenario1 function. I also get two errors.
1.Error 1 error LNK2005: "class Variables vari" (?vari@@3VVariables@@A) already defined in Source.obj C:\Users...\Desktop\Projects\ConsoleApplication1\ConsoleApplication1\Functions.obj ConsoleApplication1
2.Error 2 error LNK1169: one or more multiply defined symbols found C:\Users...\Desktop\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe ConsoleApplication1
I've tried using a new object in Functions.cpp, i get no errors but it doesn't get the same value from
cin >> vari.answer;