|
-
September 10th, 2002, 06:42 AM
#1
How to - forward declare a nested class or all within namespace?
How to - forward declare a nested class or all also within namespace, -
If there is inclusion of declared class to declared earlier in other file ? So - impossible to make a include?
Thanks.
(double side reference) ??
Like:
file1.h ----
#include "file2.h"
namespace 1_2
{
class 1
{
public:
host* member_host;
class 2{};
};
}
file2.h---
//impossible to include file1.h !!! -only forward declarations !
class host
{
class2* member; //Errors - 'class2 -undefined'
};
};#include "file2.h" #include "file2.h"
-
September 10th, 2002, 08:01 AM
#2
Since member is a class2 *, just forward declare class2.
Code:
//A.h
#include "B.h"
class A
{
B *b;
};
//B.h
class A;
class B
{
A *a;
};
-
September 10th, 2002, 08:10 AM
#3
this not works with multiple type -inclusions
this not works with type -inclusions
class - within class-within namespace.
In my sample how you can resolve that forward definition
class namespace 1_2::class1::class2;
generates "use of undefined class1" Error.??
Last edited by vgrigor3; September 10th, 2002 at 08:17 AM.
-
September 10th, 2002, 08:14 AM
#4
That's because class1 isnt't in the global namespace, but in namespace 1_2 (wich, btw, isn't a legal identifier). You have to resolve the scope, by prefixing the declaration with the name of the namespace.
Code:
class host;
namespace N{
class A
{
public:
host *host_;
class B{};
};
}
class host{
N::A::B *b_;
};
Last edited by Gabriel Fleseriu; September 10th, 2002 at 08:19 AM.
-
September 10th, 2002, 08:20 AM
#5
I had used full qualifying name, as changed in sample above,
but multiple type-inclusion not works,
than please,
can you chang you sample code to show how it must be right at
your opinion with all -namespace and nested class?
-
September 10th, 2002, 08:31 AM
#6
Code:
//file1.h
class host;
namespace N
{
class A
{
public:
host* host_;
class B{};
};
}
//file2.h
#include "file1.h"
class host
{
N::A::B* member;
};
// ???.cpp file
#include "file2.h"
//.....
-
September 10th, 2002, 08:40 AM
#7
no any forward declaration at your sample ?
Sorry, - important -
file2 must be included to class 1, by conditions
at that forward declaration of?
of N::A::B
must be..
How it can be?
Last edited by vgrigor3; September 10th, 2002 at 08:42 AM.
-
September 10th, 2002, 08:52 AM
#8
I don't see how that could work. Maybe you can rethink your design.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|