Re: Re-forward declaration of types which were already forward declared
From: Jonathan Turkanis (technews_at_kangaroologic.com)
Date: 02/15/04
- Next message: Jonathan Turkanis: "Re: String search library"
- Previous message: Peter Kragh: "Re: Conditionally copying text to string"
- In reply to: qazmlp: "Re-forward declaration of types which were already forward declared"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 15 Feb 2004 12:00:36 -0700
"qazmlp" <qazmlp1209@rediffmail.com> wrote in message:
> Is it a good style to re-forward declare the types, which were
already
> forward declared in base header file, in derived class header file?
>
>
> // base.h
> class addrClass;
> class base
> {
> public:
> virtual void setAddress(addrClass* node);
>
> // Other members
> } ;
>
>
> // derived.h
>
> // Is it a good style to forward declare addrClass here?
> // As setAddress method and hence the parameter of type 'addrClass*'
> // is from the base class, it may not be required, I suppose.
> class derived : public base
> {
> public:
> virtual void setAddress(addrClass* node);
>
> // Other members
> } ;
>
Obviously, you need to include "base.h" here, at least indirectly. It
is not necessary to forward declare addrClass, sinmce a forward
declaration will already be included.
Under some circumsances it is good programming practice to forward
decalre a class decalred by an included header, for instance, if
addrClass was just an implementation detail in "base.h" which might be
subject to change. Here it is part of the interface of a public
virtual function defined in the base class, so I don't see any reason
to redeclare it.
> And, similarly, what about #include-ing the header which has to be
> added
> only because of the Base class method signatures?
Which header? The header containing the definition of addrClass?
Definitely not needed in your example. Never include more headers than
absolutely necessary.
Jonathan
- Next message: Jonathan Turkanis: "Re: String search library"
- Previous message: Peter Kragh: "Re: Conditionally copying text to string"
- In reply to: qazmlp: "Re-forward declaration of types which were already forward declared"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|