Re: Mutual subclass dependency

Discussion in 'C++' started by Bob Hairgrove, Oct 19, 2004.

  1. On Tue, 19 Oct 2004 14:16:22 +0200, Martin Magnusson
    <> wrote:

    >I have some interdependent classes that look kind of like this:
    >
    >class M
    >{
    > class I
    > {};
    > T t;
    >};
    >
    >class T
    >{
    > M::I i;
    >};
    >
    >I know that two classes can't contain objects of each other's classes,
    >only pointers, and I suppose this is what's happening here. An object of
    >class M does contain a (number of) T objects, and each T object contains
    >a (number of) M::I objects. M::I, however, has no references to class T
    >at all.
    >
    >Question: Should this work (have I just not specified the right forward
    >declarations), or do I need to redesign this (do I need to deal with
    >pointers here instead of objects)?


    Why not make I a stand-alone class?

    --
    Bob Hairgrove
    Bob Hairgrove, Oct 19, 2004
    #1
    1. Advertising


  2. >>class M
    >>{
    >> class I
    >> {};
    >> T t;
    >>};


    Bob Hairgrove wrote:
    > Why not make I a stand-alone class?


    Mainly because I would have to do quite a bit of rewriting then, but if
    that is what's needed, that is what I'll do. Also, both M and M::I are
    templates, and if I make M::I a stand-alone class, it would need to be
    templated over one more argument. I would prefer to avoid that if there
    were a simple way.

    / martin
    Martin Magnusson, Oct 19, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jstorta
    Replies:
    3
    Views:
    441
    jstorta
    Feb 20, 2006
  2. thomas

    mutual dependency

    thomas, Oct 30, 2009, in forum: C++
    Replies:
    5
    Views:
    995
    Victor Bazarov
    Oct 30, 2009
  3. S.Volkov
    Replies:
    2
    Views:
    215
    S.Volkov
    Mar 12, 2006
  4. Trans
    Replies:
    8
    Views:
    320
    Robert Klemme
    Oct 23, 2008
  5. Fab

    Subclass of subclass

    Fab, Aug 9, 2012, in forum: C++
    Replies:
    0
    Views:
    395
Loading...

Share This Page