Mail Archives: djgpp/1997/08/02/21:32:40
Paul Derbyshire wrote:
> For every module with classes other modules use, and code as well, make
> a
> .cc and a .h file. In the .h file are some parts:
My personal style is to name C++ header files .hh, but fine so far.
> Then I have this:
>
> #ifndef _PGD_FOO_CC_
>
> extern int bar,baz;
> extern double quux;
>
> #endif
>
> to declare the global variables. In the .cc I declare _PGD_FOO_CC_ and
> thus
> the variables don't get double declared.
Uh? What problem is there with variables getting double-declared? The
standard way to do is to declare them in the header:
extern int bar;
and define them in the source file:
int bar;
Provided the header is wrapped in the preprocessing statements that
prevent double inclusion, there's no way that this can be double
declared/defined, unless you're linking in that module _twice_, which
would be asking for it anyway.
> The .cc has comments like the .h, then global variables and any class
> variables, as in
I don't see what the purpose of this is, unless you're .cc file contains a
template.
> static int fooclass::foovar=0;
Minor (well, minor to your main point here) nitpick: Static members are
_declared_ with the static keyword, but not defined with one, viz.:
class C
{
// ...
static int i;
static int f(void);
// ...
};
// ...
int C::i = 0;
int C::f(void) { /* ... */ }
Note that putting the static keyword in the definition is an error (gcc
complains, "static member '...' re-declared as static" or "cannot declare
member function '...' to have static linkage."
--
Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
Alcyone Systems / web / http://www.alcyone.com/max/
San Jose, California, United States / icbm / 37 20 07 N 121 53 38 W
\
"Love is not love which alters / when it alternation finds."
/ William Shakespeare, _Sonnets_, 116
- Raw text -