Advertisement

I fixed it, then it came back WTF!!

Started by December 10, 2002 09:16 PM
3 comments, last by Nothingness 21 years, 11 months ago
Ok I finally got my headers to work correctly. At first I was getting linker errors, then all I did was cut the .cpp and .h files and put them in another folder, and BINGO it worked. So I proceeded in attempting to code the rest of the project, but once I found that the classes I made needed more accesors and other things, I decided to delete the work I did on one of the .cpp files and restart from scratch. Once I did that I recompiled everything and started to build everything again, when the linker errors came up. I don't get what is happening, i'm sure that my code is correct but I don't get why the linker errors returned when I changed something, then returned it back the same again. Oh and while im at it, can I return more than one thing? Because I have functions that has more than one variable that I would like to return by themselves. Or would I have to rethink that and make a new way to return more than one thing? [edited by - Nothingness on December 10, 2002 10:21:15 PM]
Try to put here your linker errors.

And instead of returning two values you can use pointers i.e.

  int ValueA = 2;int ValueB = 5;int Mul;int Add;CustomFunction( ValueA, ValueB, &Mul, &Add );void CustomFunction( int A, int B, int *AddedValue, int *MultipliedValue ){   *AddedValue      = A+B;   *MultipliedValue = A*B;}  


Hope it helps.

Kamikaze
Advertisement
The linker errors are:
Linking...
main.obj : error LNK2005: "int __cdecl Direction1(int)" (?Direction1@@YAHH@Z) already defined in functions.obj
main.obj : error LNK2005: "int __cdecl Direction2(int)" (?Direction2@@YAHH@Z) already defined in functions.obj
main.obj : error LNK2005: "int __cdecl Menu(class FISH)" (?Menu@@YAHVFISH@@@Z) already defined in functions.obj
Debug/main.exe : fatal error LNK1169: one or more multiply defined symbols found
Error executing link.exe.

As I said earlier I fixed it once, and then it just came back after I added something, then deleted the part I added. And everything for the .h files are good. I have the #ifndef and #elseif things, and one cpp file has the prototype and code for each function. I did everthing correct, but when I reopened the workspace and compiled it, linker errors came up.

And for the returning of 2 things I want to return 2 booleans that tell if something is TRUE or FALSE.
Do not define non-inline functions nor non-extern variables in headers.

- Header -

int foo();
inline int bar() { return 0; }
extern int baz;

- Source -

int foo() { return 0; }
int baz;



[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | Free C++ IDE. ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Boost C++ Lib ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

    bool BoolA = true;bool BoolB = false;bool Is_Bool_A_True;bool Is_Bool_B_True;CustomFunction( BoolA, BoolB, &Is_Bool_A_True, &Is_Bool_B_True );void CustomFunction( bool A, bool B, bool *Is_A_True, bool *Is_B_True ){   if(A)      *Is_A_True = true;   else      *Is_A_True = false;   if(B)      *Is_B_True = true;   else      *Is_B_True = false;}  


Kamikaze

[edited by - Kamikaze15 on December 10, 2002 10:57:44 PM]

This topic is closed to new replies.

Advertisement