Re: Is there anyway to forward reference a namespace like STL? by Victor
Victor
Fri Aug 19 17:42:08 CDT 2005
Bruce Stemplewski wrote:
> Is there anyway to forward reference a namespace like STL?
>
> I can forward reference a class in my header file like this.
>
> class MyClass;
That's call a "forward declaration".
>
>
> class AnotherClass
> {
>
> MyClass *c;
That's just using the forward declaration. You can actually omit the
forward declaration and write
class MyClass *c;
here.
>
>
> }
>
> This way I do not need to include the header to MyClass in the header
> for AnotherClass.
>
>
> But how would I do this for something that uses a namespace like STL?
>
> std::vector< Route* > *m_coll;
There is no need to forward declare a namespace. Namespaces can be
reopened:
namespace std {
// whatever
}
but you don't really need that, do you? What you need is the ability
to forward-declare 'std::vector'... That's rather difficult because
you don't know how many and what arguments to give it.
Why can't you simply include <vector> in the file where you declare
your m_coll pointer? I know you probably don't want to, but is there
a technical reason why you can't? I bet there isn't. You could add
a forward-declaration of the 'std::vector', but in that case you will
tie yourself up with a particular implementation of it (and you really
don't want to do that, trust me). Just include the damn header.
V