Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!usc!jarthur!uci-ics!rfg From: rfg@ics.uci.edu (Ronald Guilmette) Newsgroups: comp.lang.c++ Subject: Re: Realized the error of my ways Message-ID: <2611CC5B.16631@paris.ics.uci.edu> Date: 29 Mar 90 08:50:35 GMT References: <5790@rouge.usl.edu> <10625@alice.UUCP> Reply-To: rfg@ics.uci.edu (Ronald Guilmette) Organization: UC Irvine Department of ICS Lines: 37 In article <10625@alice.UUCP> ark@alice.UUCP (Andrew Koenig) writes: >In article <5790@rouge.usl.edu>, ewe@gator.cacs.usl.edu (Edwin Wallace Elberson) writes: > >> I've got it straightened out now; I guess the problem was with my concept >> of definitions and declarations. However, after seeing what I was trying to >> do, does anyone have any tips on including the same header in files that >> are to be compiled at the same time? Being new to C++, I'd like to see what >> other people do in this situation, and how their techniques differ from >> the way I'm doing it now. Thanks, > >The short answer is: > > Suppose you have a class Foo that you want to use in > several separately compiled parts of your program. > > Create a file called Foo.h that looks like this: > > #ifndef Foo_flag > #define Foo_flag 1 > > other stuff goes here > > #endif Or, if you happen to be using the GNU g++ compiler (with the GNU preprocessor), and you are not too worried about ANSI-C compatibility, you can use a little feature that I invented (and implemented), to wit: #pragma once When this appears in an include file, the preprocessor will not include that particular file more than once during the current compilation. // Ron Guilmette (rfg@ics.uci.edu) // C++ Entomologist // Motto: If it sticks, force it. If it breaks, it needed replacing anyway.