cvs.gedasymbols.org/archives/browse.cgi   search  
Mail Archives: djgpp/1998/11/11/07:45:49

From: hat AT se-46 DOT wpa DOT wtb DOT tue DOT nl (Albert Hofkamp)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: .h files
Date: 11 Nov 1998 12:20:15 GMT
Organization: Eindhoven University of Technology, The Netherlands
Lines: 61
Message-ID: <slrn74j08d.gfk.hat@se-46.wpa.wtb.tue.nl>
References: <001301be0d11$390cd520$c5223182 AT marst96 DOT m DOT resnet DOT pitt DOT edu>
NNTP-Posting-Host: se-46.wpa.wtb.tue.nl
X-Newsreader: slrn (0.9.4.3 UNIX)
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019