[computer-go] C++: #include vs .h files

House, Jason J. jhouse at mitre.org
Wed Aug 9 14:53:56 PDT 2006


Are you using templates?
 
Assuming the answer to that is "no", the only way to get duplicate
definitions is if you actually define a variable in your header file...
for example "int x;"  The proper way to make a global variable in a
header is "extern int x;"  You must then pick a .c/.cpp file and put
"int x" in there.  Of course, global variable are not recommended...
 
Does that answer your question?


________________________________

	From: computer-go-bounces at computer-go.org
[mailto:computer-go-bounces at computer-go.org] On Behalf Of Peter Drake
	Sent: Wednesday, August 09, 2006 5:49 PM
	To: Computer Go
	Subject: [computer-go] C++: #include vs .h files
	
	
	Thanks for the quick response on the array passing. I think I
get it now. 

	I'm having a devil of a time trying to divide my classes
between .h and .cpp files. Specifically, if I have the same #include in
several .cpp files, I get complaints about redundant definitions from
the linker. I can avoid this by putting everything in the .h files
(except for one .cpp file), but then I can't define classes that depend
on each other.

	Any advice?

	
	Peter Drake
	Assistant Professor of Computer Science
	Lewis & Clark College
	http://www.lclark.edu/~drake/





-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://computer-go.org/pipermail/computer-go/attachments/20060809/e702375c/attachment.htm


More information about the computer-go mailing list