Click to See Complete Forum and Search --> : How to - forward declare a nested class or all within namespace?
vgrigor3
September 10th, 2002, 06:42 AM
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"
Gabriel Fleseriu
September 10th, 2002, 08:01 AM
Since member is a class2 *, just forward declare class2.
//A.h
#include "B.h"
class A
{
B *b;
};
//B.h
class A;
class B
{
A *a;
};
vgrigor3
September 10th, 2002, 08:10 AM
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.??
Gabriel Fleseriu
September 10th, 2002, 08:14 AM
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.
class host;
namespace N{
class A
{
public:
host *host_;
class B{};
};
}
class host{
N::A::B *b_;
};
vgrigor3
September 10th, 2002, 08:20 AM
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?
Gabriel Fleseriu
September 10th, 2002, 08:31 AM
//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"
//.....
vgrigor3
September 10th, 2002, 08:40 AM
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?
Gabriel Fleseriu
September 10th, 2002, 08:52 AM
I don't see how that could work. Maybe you can rethink your design.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.