471,873 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,873 software developers and data experts.

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 10349
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.