|
-
March 8th, 2008, 12:54 AM
#1
I'm getting Linking errors about functions already being defined in other .obj files
I'm building a console chess application that (so far) has 10 files:
(3 classes)
Move.h, Move.cpp
Piece.h, Piece.cpp
Player.h, Player.cpp
(display module contains functions used for screen output)
Display.h
Display.cpp
(header for any global variables, enums, constants, etc...)
Chess.h
(and finally the location of 'int main()' and all other functions)
Chess.cpp
Here is a breakdown of how all the files are linked together by #include directives. Of course, each header file contains inclusion guards before anything else to prevent it being compiled more than once.
Chess.cpp #includes Chess.h. Also, all three class headers #include Chess.h for the enums it contains. Then, Chess.h #includes Display.h so that Chess.cpp will have access to all those functions for displaying output. Finally, Display.h #includes several files that I didn't write like iostream, vector, time, string, windows, etc...
Is there a reason why my program only compiles when I declare all functions of the Display module in the header file (Display.h) and then define them all in the implementation file (Display.cpp)? When I try to define some of them in the header file (only the ones that are only like one line) then I get errors about those functions already being defined in another .obj file of one of the classes. Can anyone help me with this? Let me know if I need to include some code or something. I didn't know exactly how much info you'd need to help me out. Thanks in advance for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|