Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Circular references involving internal classes

Reply
Thread Tools

Circular references involving internal classes

 
 
Dave Rudolf
Guest
Posts: n/a
 
      03-05-2004
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




 
Reply With Quote
 
 
 
 
Chris \( Val \)
Guest
Posts: n/a
 
      03-05-2004

"Dave Rudolf" <> wrote in message
news:...
| 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


 
Reply With Quote
 
 
 
 
Rob Williscroft
Guest
Posts: n/a
 
      03-05-2004
Dave Rudolf wrote in news::

> 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 */
{
};


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

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

[snip]

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

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to structure classes involving friend function subramanian100in@yahoo.com, India C++ 2 04-18-2010 04:02 PM
internal circular class references Ethan Furman Python 8 12-11-2008 07:29 PM
Semi-circular definitions (plus circular references) Kiuhnm C++ 16 01-03-2005 03:49 AM
Re: Circular References Bill Jones ASP .Net 1 04-08-2004 10:16 PM
Circular references are not supported Dan C Douglas ASP .Net 1 08-13-2003 09:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57