forward declaration of a class in another namespace

D

dj

How can I make a forward declaration of a class that is defined in some
other namespace? E.g.:

file1.h:

namespace A {
class A {...};
}

file2.h:

class A::A; //error: A is not a namespace
class B {
A* a;
};


The only way I found is to include file1.h in file2.h. But in that case
I don't need a forward declaration of A anymore, because I lose the
compilation "independence" anyway.
 
T

Tom Smith

dj said:
How can I make a forward declaration of a class that is defined in some
other namespace? E.g.:

Enclose the forward declaration in a "namespace NAME { }"; ie:

// begin code

namespace C
{
class A;
}

class B
{
C::A* PointerToUnknownClass;
};

int main()
{
return 0;
}

// end code

This compiles fine on my G++. Hope that helps.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top