Linking issue, I think

I was upgrading my calculator program, and I made a header called Interface.h that handled interaction with the user, so that most of the calculator program would not know anything about the external interface, just how to get the input it needs, so that when I moved to a GUI interface, it would be a smooth transition. But, when I tried to build the solution, Visual Studio spit back some errors:

1>stdafx.obj : error LNK2005: "void __cdecl prepInputFail(void)" (?prepInputFail@@YAXXZ) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "void __cdecl ClearOutput(void)" (?ClearOutput@@YAXXZ) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "char __cdecl ReceiveChar(void)" (?ReceiveChar@@YADXZ) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "void __cdecl DisplayData(char const *,int)" (?DisplayData@@YAXPBDH@Z) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "double __cdecl ReceiveNumber(void)" (?ReceiveNumber@@YANXZ) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "void __cdecl Displayresult(double)" (?Displayresult@@YAXN@Z) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "char __cdecl SendRequest(char const *,int)" (?SendRequest@@YADPBDH@Z) already defined in CoutandCinTest2.obj
1>stdafx.obj : error LNK2005: "bool __cdecl SendaReceiveYesorNoAnswer(char const *,int)" (?SendaReceiveYesorNoAnswer@@YA_NPBDH@Z) already defined in CoutandCinTest2.obj
1>C:\Users\alex\documents\visual studio 2010\Projects\CoutandCinTest2\Debug\CoutandCinTest2.exe : fatal error LNK1169: one or more multiply defined symbols found


What am I doing wrong here?
Your headerfile has #pragma once as first line in it ? do that and then rebuild the solution.
Same errors.
You have the same function definitions (that is, the bit that actually does the work) in more than one cpp file (note that a cpp file includes the full contents of any h file you include in it). This can only be fixed by not having identical function definitions in more than one cpp file.

You can fix this by putting only the declaration of the functions in a common header, and then having the implementation of the functions in a single cpp file.
I did make it so that some functions could accept more than one argument type. One function actually has THREE definitions so it could handle lots of possible types. Ex:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
void DisplayData(char thedata, int mode) {
			switch (mode) {
			case 1: cout << endl << thedata;
			case 2: cerr << endl << thedata;
			case 3: ClearOutput(); cout << endl << thedata;
			case 4: ClearOutput(); cerr << endl << thedata;
			default: cerr << endl << "Error: Got unexpected mode number in call to DisplayData";
			}
		}
		void DisplayData(const char* thedata, int mode) {
			switch (mode) {
			case 1: cout << endl << thedata;
			case 2: cerr << endl << thedata;
			case 3: ClearOutput(); cout << endl << thedata;
			case 4: ClearOutput(); cerr << endl << thedata;
			default: cerr << endl << "Error: Got unexpected mode number in call to DisplayData";
			}
		}

		void DisplayData(string thedata, int mode) {
			switch (mode) {
			case 1: cout << endl << thedata;
			case 2: cerr << endl << thedata;
			case 3: ClearOutput(); cout << endl << thedata;
			case 4: ClearOutput(); cerr << endl << thedata;
			default: cerr << endl << "Error: Got unexpected mode number in call to DisplayData";
			}
		}

Could that cause some problems in this case?
Those functions do not conflict. Different parameter types define different functions in C++. The problem is that definitions appear in more than one cpp file, so the linker does not know which one you mean when you try to use it,
It worked, thanks!
Topic archived. No new replies allowed.