468,505 Members | 1,938 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

forward declaration of a class in another namespace

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.
Oct 6 '06 #1
1 8424
dj wrote:
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
Oct 6 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Steven T. Hatton | last post: by
5 posts views Thread by John Gabriele | last post: by
2 posts views Thread by Plok Plokowitsch | last post: by
3 posts views Thread by Libertadrian | last post: by
4 posts views Thread by yuliy | last post: by
23 posts views Thread by mark.moore | last post: by
3 posts views Thread by yancheng.cheok | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.