mutual class dependencies

Discussion in 'C++' started by mosfet, Jan 24, 2008.

  1. mosfet

    mosfet Guest

    Hi,

    I would like to write something like :

    //forward declarations
    class B;
    class A;


    class A
    {
    public:
    A()
    {

    }

    A& SetContext(B::TContext eContext)
    {
    m_eContext = eContext;
    return *this;
    }

    B::TContext m_eContext;
    };


    class B:
    {
    public:

    enum TContext
    {
    EUserMessage = 0,
    EWizzardQuestion,
    EWizzardConfirmation,
    EContextCount
    };
    }:

    But When I try I Get error C2027: use of undefined type 'B'
     
    mosfet, Jan 24, 2008
    #1
    1. Advertising

  2. * mosfet:
    > Hi,
    >
    > I would like to write something like :
    >
    > //forward declarations
    > class B;
    > class A;
    >
    >
    > class A
    > {
    > public:
    > A()
    > {
    >
    > }
    >
    > A& SetContext(B::TContext eContext)
    > {
    > m_eContext = eContext;
    > return *this;
    > }
    >
    > B::TContext m_eContext;
    > };
    >
    >
    > class B:
    > {
    > public:
    >
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    > };
    > }:
    >
    > But When I try I Get error C2027: use of undefined type 'B'


    Remove the forward declarations.

    Move class B before class A.

    Fix the syntax errors.


    Cheers, & hth.,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 24, 2008
    #2
    1. Advertising

  3. mosfet

    Guest

    On Jan 24, 10:00 am, mosfet <> wrote:
    > Hi,
    >
    > I would like to write something like :
    >
    > //forward declarations
    > class B;
    > class A;
    >
    > class A
    > {
    > public:
    >         A()
    >         {
    >
    >         }
    >
    >         A& SetContext(B::TContext eContext)
    >         {
    >                 m_eContext = eContext;
    >                 return *this;
    >         }
    >
    > B::TContext m_eContext;
    >
    > };
    >
    > class B:
    > {
    > public:
    >
    > enum TContext
    >         {
    >                 EUserMessage = 0,
    >                 EWizzardQuestion,
    >                 EWizzardConfirmation,
    >                 EContextCount
    >         };
    >
    > }:
    >
    > But When I try I Get error C2027: use of undefined type 'B'


    You use B as a member of A so the compiler needs to have the
    complete declaration of B.

    You can include the B header file (instead of forward declaring
    it). Also, possible solution is to have A contain a pointer to
    B instead of a B.

    HTH
     
    , Jan 24, 2008
    #3
  4. mosfet

    mosfet Guest

    Alf P. Steinbach a écrit :
    > * mosfet:
    >> Hi,
    >>
    >> I would like to write something like :
    >>
    >> //forward declarations
    >> class B;
    >> class A;
    >>
    >>
    >> class A
    >> {
    >> public:
    >> A()
    >> {
    >> }
    >> A& SetContext(B::TContext eContext)
    >> {
    >> m_eContext = eContext;
    >> return *this;
    >> }
    >>
    >> B::TContext m_eContext;
    >> };
    >>
    >>
    >> class B:
    >> {
    >> public:
    >>
    >> enum TContext
    >> {
    >> EUserMessage = 0,
    >> EWizzardQuestion,
    >> EWizzardConfirmation,
    >> EContextCount
    >> };
    >> }:
    >>
    >> But When I try I Get error C2027: use of undefined type 'B'

    >
    > Remove the forward declarations.
    >
    > Move class B before class A.
    >
    > Fix the syntax errors.
    >
    >
    > Cheers, & hth.,
    >
    > - Alf
    >

    Oups I forgot to say that class B includes a A object:


    class A
    {
    public:
    A()
    {

    }

    A& SetContext(B::TContext eContext)
    {
    m_eContext = eContext;
    return *this;
    }

    B::TContext m_eContext;
    };



    class B:
    {
    public:
    enum TContext
    {
    EUserMessage = 0,
    EWizzardQuestion,
    EWizzardConfirmation,
    EContextCount
    };

    protected:

    A m_A;

    }:


    So I cannot do what you say.
     
    mosfet, Jan 24, 2008
    #4
  5. * mosfet:
    > Alf P. Steinbach a écrit :
    >> * mosfet:
    >>> Hi,
    >>>
    >>> I would like to write something like :
    >>>
    >>> //forward declarations
    >>> class B;
    >>> class A;
    >>>
    >>>
    >>> class A
    >>> {
    >>> public:
    >>> A()
    >>> {
    >>> }
    >>> A& SetContext(B::TContext eContext)
    >>> {
    >>> m_eContext = eContext;
    >>> return *this;
    >>> }
    >>>
    >>> B::TContext m_eContext;
    >>> };
    >>>
    >>>
    >>> class B:
    >>> {
    >>> public:
    >>>
    >>> enum TContext
    >>> {
    >>> EUserMessage = 0,
    >>> EWizzardQuestion,
    >>> EWizzardConfirmation,
    >>> EContextCount
    >>> };
    >>> }:
    >>>
    >>> But When I try I Get error C2027: use of undefined type 'B'

    >>
    >> Remove the forward declarations.
    >>
    >> Move class B before class A.
    >>
    >> Fix the syntax errors.
    >>
    >>
    >> Cheers, & hth.,
    >>
    >> - Alf
    >>

    > Oups I forgot to say that class B includes a A object:
    >
    >
    > class A
    > {
    > public:
    > A()
    > {
    >
    > }
    >
    > A& SetContext(B::TContext eContext)
    > {
    > m_eContext = eContext;
    > return *this;
    > }
    >
    > B::TContext m_eContext;
    > };
    >
    >
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    > };
    >
    > protected:
    >
    > A m_A;
    >
    > }:
    >
    >
    > So I cannot do what you say.


    Oups I forgot to say that if the requirements change, change the
    solution accordingly.


    Cheers, & hth.

    - Alf


    PS: Don't forget to fix the syntax errors.


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 24, 2008
    #5
  6. mosfet

    Salt_Peter Guest

    On Jan 24, 10:18 am, mosfet <> wrote:
    > Alf P. Steinbach a écrit :
    >
    > > * mosfet:
    > >> Hi,

    >
    > >> I would like to write something like :

    >
    > >> //forward declarations
    > >> class B;
    > >> class A;

    >
    > >> class A
    > >> {
    > >> public:
    > >> A()
    > >> {
    > >> }
    > >> A& SetContext(B::TContext eContext)
    > >> {
    > >> m_eContext = eContext;
    > >> return *this;
    > >> }

    >
    > >> B::TContext m_eContext;
    > >> };

    >
    > >> class B:
    > >> {
    > >> public:

    >
    > >> enum TContext
    > >> {
    > >> EUserMessage = 0,
    > >> EWizzardQuestion,
    > >> EWizzardConfirmation,
    > >> EContextCount
    > >> };
    > >> }:

    >
    > >> But When I try I Get error C2027: use of undefined type 'B'

    >
    > > Remove the forward declarations.

    >
    > > Move class B before class A.

    >
    > > Fix the syntax errors.

    >
    > > Cheers, & hth.,

    >
    > > - Alf

    >
    > Oups I forgot to say that class B includes a A object:
    >
    > class A
    > {
    > public:
    > A()
    > {
    >
    > }
    >
    > A& SetContext(B::TContext eContext)
    > {
    > m_eContext = eContext;
    > return *this;
    > }
    >
    > B::TContext m_eContext;
    >
    > };
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    >
    > };
    >
    > protected:
    >
    > A m_A;
    >
    > }:
    >
    > So I cannot do what you say.


    ...unfortunately for you.
    If type A has a member B and a type B has a member A (which has a B
    which has an A .... ad infinitum) then the program has no way to
    define concretely the resulting type.

    However, you could have a type A as a member of type B and use a
    pointer to B in type A.
     
    Salt_Peter, Jan 24, 2008
    #6
  7. mosfet

    Puppet_Sock Guest

    On Jan 24, 10:18 am, mosfet <> wrote:
    > Alf P. Steinbach a écrit :
    >
    >
    >
    > > * mosfet:
    > >> Hi,

    >
    > >> I would like to write something like :

    >
    > >> //forward declarations
    > >> class B;
    > >> class A;

    >
    > >> class A
    > >> {
    > >> public:
    > >>     A()
    > >>     {
    > >>            }
    > >>         A& SetContext(B::TContext eContext)
    > >>     {
    > >>         m_eContext = eContext;
    > >>         return *this;
    > >>     }

    >
    > >> B::TContext m_eContext;
    > >> };

    >
    > >> class B:
    > >> {
    > >> public:

    >
    > >> enum TContext
    > >>     {
    > >>         EUserMessage = 0,
    > >>         EWizzardQuestion,
    > >>         EWizzardConfirmation,
    > >>         EContextCount
    > >>     };
    > >> }:

    >
    > >> But When I try I Get error C2027: use of undefined type 'B'

    >
    > > Remove the forward declarations.

    >
    > > Move class B before class A.

    >
    > > Fix the syntax errors.

    >
    > > Cheers, & hth.,

    >
    > > - Alf

    >
    > Oups I forgot to say that class B includes a A object:
    >
    > class A
    > {
    > public:
    >      A()
    >      {
    >
    >      }
    >
    >      A& SetContext(B::TContext eContext)
    >      {
    >          m_eContext = eContext;
    >          return *this;
    >      }
    >
    > B::TContext m_eContext;
    >
    > };
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    >
    > };
    >
    > protected:
    >
    > A  m_A;
    >
    > }:
    >
    > So I cannot do what you say.


    And, of course, the world would come to an end if you moved
    that enum out of class B.
    Socks
     
    Puppet_Sock, Jan 24, 2008
    #7
  8. > class A
    > {
    > public:
    > A()
    > {
    >
    > }
    >
    > A& SetContext(B::TContext eContext)
    > {
    > m_eContext = eContext;
    > return *this;
    > }
    >
    > B::TContext m_eContext;
    > };
    >
    >
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    > };
    >
    > protected:
    >
    > A m_A;
    >
    > }:


    You need to break the circular dependencies somewhere, and there are
    several options. How about:

    enum B_TContext { EUserMessage = 0 ...... };

    class A {
    A& SetContext(B_TContext eContent) ....
    B_TContext m_eContext;
    };

    class B {
    typedef B_TContext TContext;
    A m_A;
    };
     
    Phil Endecott, Jan 24, 2008
    #8
  9. mosfet

    jalina Guest

    Puppet_Sock a écrit :
    > On Jan 24, 10:18 am, mosfet <> wrote:
    >> Alf P. Steinbach a écrit :
    >>
    >>
    >>
    >>> * mosfet:
    >>>> Hi,
    >>>> I would like to write something like :
    >>>> //forward declarations
    >>>> class B;
    >>>> class A;
    >>>> class A
    >>>> {
    >>>> public:
    >>>> A()
    >>>> {
    >>>> }
    >>>> A& SetContext(B::TContext eContext)
    >>>> {
    >>>> m_eContext = eContext;
    >>>> return *this;
    >>>> }
    >>>> B::TContext m_eContext;
    >>>> };
    >>>> class B:
    >>>> {
    >>>> public:
    >>>> enum TContext
    >>>> {
    >>>> EUserMessage = 0,
    >>>> EWizzardQuestion,
    >>>> EWizzardConfirmation,
    >>>> EContextCount
    >>>> };
    >>>> }:
    >>>> But When I try I Get error C2027: use of undefined type 'B'
    >>> Remove the forward declarations.
    >>> Move class B before class A.
    >>> Fix the syntax errors.
    >>> Cheers, & hth.,
    >>> - Alf

    >> Oups I forgot to say that class B includes a A object:
    >>
    >> class A
    >> {
    >> public:
    >> A()
    >> {
    >>
    >> }
    >>
    >> A& SetContext(B::TContext eContext)
    >> {
    >> m_eContext = eContext;
    >> return *this;
    >> }
    >>
    >> B::TContext m_eContext;
    >>
    >> };
    >>
    >> class B:
    >> {
    >> public:
    >> enum TContext
    >> {
    >> EUserMessage = 0,
    >> EWizzardQuestion,
    >> EWizzardConfirmation,
    >> EContextCount
    >>
    >> };
    >>
    >> protected:
    >>
    >> A m_A;
    >>
    >> }:
    >>
    >> So I cannot do what you say.

    >
    > And, of course, the world would come to an end if you moved
    > that enum out of class B.
    > Socks


    People answering in this newsgroup is so nice and well minded.

    Everyone who is a newbye or not aware of usenet usage have such
    "pleasant" answers from some people that are so clever (and certainly
    think that the noobs posting dumb....s only deserve contempt - just read
    their "nice" answers)

    Perhaps rename this newgroup to something like comp.land.advanced.c++ so
    that noobs don't get to post there. I guess that between clever people,
    contempt does not matter.

    I have decided to boycott this newsgroup and I am going to start an
    campaign to inform people not to read and post here.

    Jalina
     
    jalina, Jan 24, 2008
    #9
  10. mosfet

    jalina Guest

    Alf P. Steinbach a écrit :
    > * mosfet:
    >> Alf P. Steinbach a écrit :
    >>> * mosfet:
    >>>> Hi,
    >>>>
    >>>> I would like to write something like :
    >>>>
    >>>> //forward declarations
    >>>> class B;
    >>>> class A;
    >>>>
    >>>>
    >>>> class A
    >>>> {
    >>>> public:
    >>>> A()
    >>>> {
    >>>> }
    >>>> A& SetContext(B::TContext eContext)
    >>>> {
    >>>> m_eContext = eContext;
    >>>> return *this;
    >>>> }
    >>>>
    >>>> B::TContext m_eContext;
    >>>> };
    >>>>
    >>>>
    >>>> class B:
    >>>> {
    >>>> public:
    >>>>
    >>>> enum TContext
    >>>> {
    >>>> EUserMessage = 0,
    >>>> EWizzardQuestion,
    >>>> EWizzardConfirmation,
    >>>> EContextCount
    >>>> };
    >>>> }:
    >>>>
    >>>> But When I try I Get error C2027: use of undefined type 'B'
    >>>
    >>> Remove the forward declarations.
    >>>
    >>> Move class B before class A.
    >>>
    >>> Fix the syntax errors.
    >>>
    >>>
    >>> Cheers, & hth.,
    >>>
    >>> - Alf
    >>>

    >> Oups I forgot to say that class B includes a A object:
    >>
    >>
    >> class A
    >> {
    >> public:
    >> A()
    >> {
    >>
    >> }
    >>
    >> A& SetContext(B::TContext eContext)
    >> {
    >> m_eContext = eContext;
    >> return *this;
    >> }
    >>
    >> B::TContext m_eContext;
    >> };
    >>
    >>
    >>
    >> class B:
    >> {
    >> public:
    >> enum TContext
    >> {
    >> EUserMessage = 0,
    >> EWizzardQuestion,
    >> EWizzardConfirmation,
    >> EContextCount
    >> };
    >>
    >> protected:
    >>
    >> A m_A;
    >>
    >> }:
    >>
    >>
    >> So I cannot do what you say.

    >
    > Oups I forgot to say that if the requirements change, change the
    > solution accordingly.
    >
    >
    > Cheers, & hth.
    >
    > - Alf
    >
    >
    > PS: Don't forget to fix the syntax errors.
    >
    >

    People answering in this newsgroup is so nice and well minded.

    Everyone who is a newbye or not aware of usenet usage have such
    "pleasant" answers from some people that are so clever (and certainly
    think that the noobs posting dumb....s only deserve contempt - just read
    their "nice" answers)

    Perhaps rename this newgroup to something like comp.land.advanced.c++ so
    that noobs don't get to post there. I guess that between clever people,
    contempt does not matter.

    I have decided to boycott this newsgroup and I am going to start an
    campaign to inform people not to read and post here.

    Jalina
     
    jalina, Jan 24, 2008
    #10
  11. "jalina" <> wrote in message
    news:4798d766$0$862$...
    [...]
    > I have decided to boycott this newsgroup and I am going to start an
    > campaign to inform people not to read and post here.


    Don't you have any other ways to waste your time?
     
    Chris Thomasson, Jan 24, 2008
    #11
  12. jalina wrote:

    >
    > I have decided to boycott this newsgroup and I am going to start an
    > campaign to inform people not to read and post here.


    start now - you posted this message twice already.
     
    James Connell, Jan 25, 2008
    #12
  13. mosfet

    Jack Klein Guest

    Jack Klein, Jan 25, 2008
    #13
  14. mosfet

    anon Guest

    jalina wrote:
    > I have decided to boycott this newsgroup and I am going to start an
    > campaign to inform people not to read and post here.


    Cool. Start with nike sellers, free sex messages, free money sites, and
    similar people.
     
    anon, Jan 25, 2008
    #14
  15. * anon:
    > jalina wrote:
    >> I have decided to boycott this newsgroup and I am going to start an
    >> campaign to inform people not to read and post here.

    >
    > Cool. Start with nike sellers, free sex messages, free money sites, and
    > similar people.


    Well, I think "jalina" had a point, although he/she may not have and
    probably have not (yet) realized it.

    Namely, that reading a technical discussion as if it were emotional
    hinting and come-uppance (not that it isn't, sometimes!) is in general
    very counter-productive. Technical accuracy is very important for
    technical stuff. And as it happens, which is a bit ironic, that was my
    message.

    FAQ item 5.8 "How do I post a question about code that doesn't work
    correctly", found at e.g. <url:
    http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.8>, gives
    some concrete advice about how to achieve technical accuracy when
    posting, and hence ensuring more accurate answers and not wasting
    other's time, and perhaps I should just have referred to that FAQ item
    (I would if I'd known there was such a sensitive reader lurking! :) ).

    Cheers,

    - Alf

    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jan 25, 2008
    #15
  16. mosfet

    Grizlyk Guest

    mosfet wrote:
    >
    > >> //forward declarations
    > >> class B;
    > >> class A;

    >
    > >> class A
    > >> {
    > >> public:
    > >>     A()
    > >>     {
    > >>            }
    > >>         A& SetContext(B::TContext eContext)

    >
    > >> But When I try I Get error C2027: use of undefined type 'B'

    >
    > class B includes a A object:


    It is evidently, you need TContext type completely declared, because
    of you need to know sizeof(TContext) to pass eContext by value.

    You can pass eContext by reference
    A& SetContext(B::TContext& eContext)

    or remove declaration of TContext into separated class

    namespace NB{
    class TContext
    {
    //
    };
    }

    //forward declarations
    class A;
    class B;
    //using NB::TContext;

    Maksim A. Polyanin
    http://grizlyk1.narod.ru/cpp_new
     
    Grizlyk, Jan 26, 2008
    #16
  17. On Jan 24, 10:18 am, mosfet <> wrote:
    > Alf P. Steinbach a écrit :
    >


    > >> But When I try I Get error C2027: use of undefined type 'B'

    >
    > > Remove the forward declarations.

    >
    > > Move class B before class A.

    >
    > > Fix the syntax errors.

    >
    > > Cheers, & hth.,

    >
    > > - Alf

    >
    > Oups I forgot to say that class B includes a A object:
    >
    > class A
    > {
    > public:
    >      A()
    >      {
    >
    >      }
    >
    >      A& SetContext(B::TContext eContext)
    >      {
    >          m_eContext = eContext;
    >          return *this;
    >      }
    >
    > B::TContext m_eContext;
    >
    > };
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    >
    > };
    >
    > protected:
    >
    > A  m_A;
    >
    > }:
    >
    > So I cannot do what you say.


    Include A and B as references. That way you can use forward
    declarations to take care of the cyclic dependencies.

    The following article should help:
    http://www.eventhelix.com/RealtimeMantra/HeaderFileIncludePatterns.htm

    --
    EventStudio 4.0 - http://www.Eventhelix.com/Eventstudio/
    Sequence diagram based systems engineering tool
     
    EventHelix.com, Jan 26, 2008
    #17
  18. mosfet

    Grizlyk Guest

    jalina wrote:
    >
    > I have decided to boycott this newsgroup and I am going to start an
    > campaign to inform people not to read and post here.


    Do not pay any attention at the rancorous men, just because:
    1. they cheafly do not give you any useful in C++ scope;
    2. it is not easy for anybody (though i do not acquit any evil
    behavior) to read and answer in a group, especially when there are
    tons of questions, that can be easy answered without any questions by
    posters itself.

    Maksim A. Polyanin
    http://grizlyk1.narod.ru/cpp_new
     
    Grizlyk, Jan 26, 2008
    #18
  19. mosfet

    Grizlyk Guest

    Grizlyk wrote:
    >
    > > >> //forward declarations
    > > >> class B;
    > > >> class A;

    >
    > > >> class A
    > > >> {
    > > >> public:
    > > >>     A()
    > > >>     {
    > > >>            }
    > > >>         A& SetContext(B::TContext eContext)

    >
    > You can pass eContext by reference
    > A& SetContext(B::TContext& eContext)


    Well, looks like useless advice here, because B::TContext must be
    declared. You can not declare B::TContext like this (i do not know
    why)

    class B;
    //using B::C;
    //class B::C;

    but you can use template<> to delay declaration

    template<typename T=B>
    class A
    {
    public:
    A& SetContext(T::TContext& eContext);
    };

    template<typename T> //(T=B is not allowed)
    void ::foo(T::TContext& c)
    {
    A<T> a;
    a.SetContext(c);
    }

    class B
    {
    public:
    //can be declared only for references
    class TContext;
    };

    void ::boo(B::TContext& c)
    {
    foo<B>(c);
    }

    > or remove declaration of TContext into separated class


    And yet, instead of using B::TContext& reference, you can move body of
    SetContext function outside of class A scope and place the body after
    B::TContext complete declaration, but the declaration of SetContext
    with eContext passed by value will touch you in code like this

    void ::foo(B::TContext& b)
    {
    A a;
    a.SetContext(b);
    }

    if the code ::foo will be placed befor B::TContext complete
    declaration.

    Maksim A. Polyanin
    http://grizlyk1.narod.ru/cpp_new
     
    Grizlyk, Jan 26, 2008
    #19
  20. mosfet

    Pavel Guest

    mosfet wrote:
    > Alf P. Steinbach a écrit :
    >> * mosfet:
    >>> Hi,
    >>>
    >>> I would like to write something like :
    >>>
    >>> //forward declarations
    >>> class B;
    >>> class A;
    >>>
    >>>
    >>> class A
    >>> {
    >>> public:
    >>> A()
    >>> {
    >>> }
    >>> A& SetContext(B::TContext eContext)
    >>> {
    >>> m_eContext = eContext;
    >>> return *this;
    >>> }
    >>>
    >>> B::TContext m_eContext;
    >>> };
    >>>
    >>>
    >>> class B:
    >>> {
    >>> public:
    >>>
    >>> enum TContext
    >>> {
    >>> EUserMessage = 0,
    >>> EWizzardQuestion,
    >>> EWizzardConfirmation,
    >>> EContextCount
    >>> };
    >>> }:
    >>>
    >>> But When I try I Get error C2027: use of undefined type 'B'

    >>
    >> Remove the forward declarations.
    >>
    >> Move class B before class A.
    >>
    >> Fix the syntax errors.
    >>
    >>
    >> Cheers, & hth.,
    >>
    >> - Alf
    >>

    > Oups I forgot to say that class B includes a A object:
    >
    >
    > class A
    > {
    > public:
    > A()
    > {
    >
    > }
    >
    > A& SetContext(B::TContext eContext)
    > {
    > m_eContext = eContext;
    > return *this;
    > }
    >
    > B::TContext m_eContext;
    > };
    >
    >
    >
    > class B:
    > {
    > public:
    > enum TContext
    > {
    > EUserMessage = 0,
    > EWizzardQuestion,
    > EWizzardConfirmation,
    > EContextCount
    > };
    >
    > protected:
    >
    > A m_A;
    >
    > }:
    >
    >
    > So I cannot do what you say.
    >


    That is an interesting problem, actually. Mixing in some templates
    compiled for me (not that I enjoyed using templates for the wrong cause):

    template<typename ThatEnum>
    class A_GENERIC {
    public: A_GENERIC() {}

    A_GENERIC &
    SetContext(ThatEnum eContext)
    {
    m_eContext = eContext;
    return *this;
    }

    ThatEnum m_eContext;
    };

    class B
    {
    public:
    enum TContext
    {
    EUserMessage = 0,
    EWizzardQuestion,
    EWizzardConfirmation,
    EContextCount
    };

    protected:

    A_GENERIC<B::TContext> m_A;

    };


    typedef A_GENERIC<B::TContext> A;

    // at this point, we have regular (non-template) A, B and B::TContext as
    ordered..

    int main(int argc, char *argv[]) {
    A a;
    a.SetContext(B::EUserMessage);
    B b;
    return 0;
    }

    Hope this will help -- but I wonder if there can be a non-template solution.

    -Pavel
     
    Pavel, Jan 29, 2008
    #20
    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. Vjeran Marcinko

    Mutual EJB possible?

    Vjeran Marcinko, Oct 17, 2003, in forum: Java
    Replies:
    3
    Views:
    461
    Michael Borgwardt
    Oct 17, 2003
  2. Giambattista Bloisi

    non-blocking mutual exclusion

    Giambattista Bloisi, Dec 16, 2003, in forum: Java
    Replies:
    1
    Views:
    422
    Matt Humphrey
    Dec 16, 2003
  3. Bob Hairgrove

    Re: Mutual subclass dependency

    Bob Hairgrove, Oct 19, 2004, in forum: C++
    Replies:
    1
    Views:
    398
    Martin Magnusson
    Oct 19, 2004
  4. .
    Replies:
    0
    Views:
    607
  5. Anonimo
    Replies:
    8
    Views:
    330
    Öö Tiib
    Mar 16, 2011
Loading...

Share This Page