|
|||||||
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
#1 |
|
Member (10 bit)
|
I am now so confused about source files and header files....
I have object A, defined in "A.cpp" I have object B, defined in "B.cpp". Object B needs to know about object A to work. So, along with the header files at the top of "B.cpp", I have the text, #include "A.cpp" Next, I have object C, defined in "C.cpp" Object C needs to know about both A and B to work. So, along with its header includes, I have the text, #include "A.cpp" #include "B.cpp" Now I know the reason for this not working, its because the includes have made the program define object A twice, and it doesn't like the redefinition. How do I get around this? The only reason I've put all of these objects in different files is for neatness. Thanks again for the help!
__________________
Desktop | Antec Performance Plus 1080AMG | Antec 430W PSU | Intel D875PBZ | Intel P4 3.0C | | 4x512 MB dual-channel DDR400 Kingston HyperX | ATI Radeon 9800 pro 256 MB | Creative Sound Blaster Audigy Gamer | | LiteOn DVD-ROM | LiteOn CDRW | 36 GB WD Raptor | 250 GB WD SATA2 | Sony Floppy | XP pro | |
|
|
|
|
|
#2 |
|
Member (10 bit)
|
hmm...i know someone who knows this stuff. ill get back 2 ya tonite.
|
|
|
|
|
|
#3 |
|
Professional gadfly
|
First of all, you should be including headers, not the actual code files. So separate the function declarations from the codes into header files (A.h, B.h, C.h)
In A.h, leave as is. In B.h, do something like this, replacing #include <A.h>: Code:
#ifndef INCLUDEA #define INCLUDEA #include <A.h> #endif Thus, when you compile C, it will include B.h, which will include A.h because INCLUDEA hasn't been defined yet. However, it won't include A.h again in C. |
|
|
|
|
|
#4 |
|
Member (10 bit)
|
So, in the class definitions, the functions will be named, but not defined (prototyped)?
And then in the header files, the functions will be defined? Thanks for the help, I think I can figure this out now. |
|
|
|
|
|
#5 |
|
Member (10 bit)
|
Okay, so far this is what I've done.
I've changed the function definitions inside the cpp code to the form: classname::functionname() { functiondefinition, return value; } and I've made .h files with prototypes of the form: returntype functionname(); with a .h file for each class, prototyping all of its PUBLIC functions. I then used your defining routine in both the cpp file that NEEDS the definition, and the cpp file whos class' functions are defined in the .h file. It still won't compile! Thanks for your patience. |
|
|
|
|
|
#6 |
|
Professional gadfly
|
What error are you getting from the compiler?
|
|
|
|
|
|
#7 |
|
Member (10 bit)
|
It says that my first object defined (it would be of class C in our example) is an unrecognized type.
|
|
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|