C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

namespaces und innere klassen

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German)
View previous topic :: View next topic  
Author Message
Alex Muffmolch
Guest





PostPosted: Tue May 04, 2004 2:26 pm    Post subject: namespaces und innere klassen Reply with quote



hallo

folgendes problem...
wir sind gerade dabei unser projekt mit namespaces in bereiche zu
kappseln.

hier bei habe ich ein grosses problem

1. mit und ohne namespaces kann es durchaus vorkommen, dass zwei
klassen abhängig voneinander sind und sich gegenseitig "includen"
-> compiler fehler, weil z.B. klasse A in B nicht bekannt oder
umgekehrt:

"a.h":
#include "b.h"
class A
{
...
B* test;
};

"b.h":
#include "a.h"
class B
{
...
A* test;
};

diesem proble entgegnet man durch die deklaration von klasse B in A
und umgekehrt, z.B.
"a.h":
class B;
class A
{
...
B* test;
};

dann funktioniert es. man kann zwar nur pointer auf die noch
unbekannten
Typen im header erzeugen, aber der compiler weiß, dass eine definition
noch kommen müsste.

2. namespace:

namespace NS_A
{
class A
{
class innerA
{ ... };
};

}

namespace NS_B
{
class B
{
innerA* foo();
};
}

hier ist das problem... der compiler kennt bei mir zum
kompilierzeitpunkt
die klasse B die klasse innerA nicht.
nun habe ich versucht im diese bekannt zu machen durch:
unsing namespace NS_A;
class A::innerA; -> A Keine Klasse oder Namespace

also hab ich
class A;
class A::innerA; angegeben -> Verwendung des undefinierten Typs
"NS_A::A"

auch funktioniert es nicht "innerA* foo()" in NS_A::A::innerA* foo()"
umzubennen.

wie löst man derartige probleme?
und wie löst man problem 1. bei namespaces im allgemeinen???

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de
Back to top
helmut zeisel
Guest





PostPosted: Fri May 07, 2004 2:53 pm    Post subject: Re: namespaces und innere klassen Reply with quote



Alex Muffmolch wrote:
Quote:
hallo

folgendes problem...
wir sind gerade dabei unser projekt mit namespaces in bereiche zu
kappseln.

hier bei habe ich ein grosses problem

Nein, Dein Problem sind nested classes.

Quote:
diesem proble entgegnet man durch die deklaration von klasse B in A
und umgekehrt, z.B.
"a.h":
class B;

Dann haettest Du eben analog
namespace NS_B
{
class B;
}

Quote:
class A
{
...
B* test;
};

Bei Namespaces eben NS_B::B* test;

Quote:
class A::innerA; angegeben -> Verwendung des undefinierten Typs
"NS_A::A"

Genau. Das liegt aber nicht am Namespace, sondern an nested classes.
Nested Classes erlauben keine Vorwärtsdeklaration; A::innerA muss eben
eine "outerA" werden. Das hat aber nichts mit Namespaces zu tun.

Helmut

--
de.comp.lang.iso-c++ - Moderation: mailto:voyager+mod (AT) bud (DOT) prima.de
FAQ: http://www.voyager.prima.de/cpp/ mailto:voyager+send-faq (AT) bud (DOT) prima.de

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ (German) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.