Re: Is there anyway to forward reference a namespace like STL?



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
.



Relevant Pages

  • Re: LNK2001: unresolved external
    ... > class MyClass ... claiming that it cant find CMyClass's destructor. ... > Strip out the destructor from the original CPP and move it to the header ...
    (microsoft.public.vc.mfc)
  • Re: Is it good programming to set instance in class without using C-tor
    ... I have a class definition called MyClass see below. ... I create an instance of this class MyClass ... the question of what arguments should go on the constructor is ... your client has to test before they try to use an object instance. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Object creation overhead
    ... > class MyClass ... This is, of course, over and above the memory required for the ... > 'MyClass' objects themselves. ... > The 'proxy' class approach won't see a reduction in the number of ...
    (comp.lang.java)
  • Re: Changed class
    ... public int value1=0; ... private int oldvalue1=0; ... MyClass nn = new MyClass ... Class MyClass {public int value1=0; ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: super.clone() puzzlement
    ... public class MyClass { ... public MyClass(MyClass mine) { ... That is, I want a copy of the MyClass instance where, when I change the object referenced by its value, a copy I've made of the MyClass instance keeps its own value object intact. ... public MyClass(T value, ValueCopier<T> copier) { ...
    (comp.lang.java.programmer)

Loading