Mail Archives: djgpp/1998/11/11/07:45:49
On Tue, 10 Nov 1998 20:18:41 -0500, mark reed <marst96+@pitt.edu> 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 !
- Raw text -