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 

Circular references involving internal classes

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
Dave Rudolf
Guest





PostPosted: Fri Mar 05, 2004 3:55 am    Post subject: Circular references involving internal classes Reply with quote



Hey all,

I have a philosophical question for you folks -- that is, I don't really
need an immediate solution, but rather I am just curious.

Is there some way to make forward declarations for internal classes. The
situlation that I have is probably best illustrated with some code:


// legal forward declaration
class B;


// illegal forward declaration
// class B::Bi;

class A
{
B _b;
// B::Bi _bi;
};


class B
{
class Bi
{
};

A _a;
};


Let's forget that the above code is probably not the best design. Now, if I
want class A to handle references to class B, I can do the normal forward
declaration thing before class A, as above. But what if I want to reference
B's inner class, as suggested by the commented-out code? Is there any way to
do such a thing?

Of course, the work-around could be to move the inner class into it's own
class. Like I said, I'm just curious.

Dave




Back to top
Chris ( Val )
Guest





PostPosted: Fri Mar 05, 2004 11:27 am    Post subject: Re: Circular references involving internal classes Reply with quote




"Dave Rudolf" <nuclearwhippingboy (AT) hotmail (DOT) com> wrote

Quote:
Hey all,

I have a philosophical question for you folks -- that is, I don't really
need an immediate solution, but rather I am just curious.

Is there some way to make forward declarations for internal classes. The
situlation that I have is probably best illustrated with some code:


// legal forward declaration
class B;


// illegal forward declaration
// class B::Bi;

class A
{
B _b;
// B::Bi _bi;
};


class B
{
class Bi
{
};

A _a;
};


Let's forget that the above code is probably not the best design. Now, if I
want class A to handle references to class B, I can do the normal forward
declaration thing before class A, as above. But what if I want to reference
B's inner class, as suggested by the commented-out code? Is there any way to
do such a thing?

Of course, the work-around could be to move the inner class into it's own
class. Like I said, I'm just curious.

Use a pointer to the objects:

class B;
class Bi;

class A
{
B* _b;
Bi* _bi;
};

Cheers.
Chris Val



Back to top
Rob Williscroft
Guest





PostPosted: Fri Mar 05, 2004 11:35 am    Post subject: Re: Circular references involving internal classes Reply with quote



Dave Rudolf wrote in news:104fuhe7ct02o21 (AT) corp (DOT) supernews.com:

Quote:
Hey all,

I have a philosophical question for you folks -- that is, I don't
really need an immediate solution, but rather I am just curious.

Is there some way to make forward declarations for internal classes.

No, though you can do this:

class Outer
{
class Inner; /* kinda forward declare */
};

class Outer::Inner /* define */
{
};


Quote:
The situlation that I have is probably best illustrated with some
code:


// legal forward declaration
class B;


// illegal forward declaration
// class B::Bi;

class A
{

This is illegal too, B is an *incomplete* type, you can declare
pointers and references to B (B*, B& etc) but not B's.

Quote:
B _b;
// B::Bi _bi;
};

[snip]


Rob.
--
http://www.victim-prime.dsl.pipex.com/

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) 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.