Message-ID: <004c01be0e57$ffc9a020$c5223182@marst96.m.resnet.pitt.edu> From: "mark reed" To: Subject: Re: .h files Date: Thu, 12 Nov 1998 11:17:50 -0500 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.1 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 Reply-To: djgpp AT delorie DOT com Thats what i meant :) I do everything just like that, x.h declares a bunch of functions, x.cpp dfines them, and main.cpp uses them. x.cpp includes x.h, and main.cpp includes x.h. but when i build using RHIDE, it says undefined reference to all my functions that main.cpp uses from x.h. I have always just had one big .h file, but going back to find things and look over my code, one big .h gets annoying to search through. So I have never had this problem before. Do i have to do something special like specify x.cpp in the commandline when i compile main.cpp? Everyone else splits the .h and .cpp and has no problems? >On Tue, 10 Nov 1998 20:18:41 -0500, mark reed wrote: >>I have a .h file and a .cpp file, the .h file contains function definitions >>for the .cpp file. How do i use those funcions in my main .cpp file?? I > >Normally, you don't have definitions in your .h file, you put declarations >in it, and put your definitions in the .cpp file. > >As an illustration: > >x.h: >------------ >void myfunc(); > >class myclass { >public: > myclass(); > ~myclass(); > // etc >}; >------------ >With these DECLARATIONS, you basically say 'these things exist >somewhere, you can use them if you like'. >To make our life easier, we define them in the .cpp file, but this is >not required. > >x.cpp: >------------ >#include "x.h" > >void myfunc() { bla bla; return; } > >myclass::myclass() { bla bla; } >myclass::~myclass() { bla bla; } >// etc >------------ >In the .cpp file, you explain to the compiler (with the DEFINITIONS) >'how it works'. >Note that I included the x.h file. This is just to make sure I >don't make mistakes without being warned by the compiler. > >in another.cpp: >------------ >#include "x.h" >// now the compiler knows about class myclass, and myfunc, and you can >// use them > >int main() { > myclass *p; > > myfunc(); // call myfunc > p = new myclass; > delete p; > return 0; >} > > >Albert >--- >The @wtb.tue.nl domain is known to bounce mail incorrectly sometimes. >If you are one of the lucky persons, please try again, and send the log >as well, so I can prove it to our postmaster. Thank you ! >