Completing type of the class

Discussion in 'C++' started by mscava@gmail.com, Feb 15, 2007.

  1. Guest

    I have 2 classes - Widget and Dialog. Dialog IS Widget. It contains
    vector of Widgets. Widget get passed pointer to Dialog in constructor.
    So both classes need to know about themselves.

    //------------------------------------------------------------------
    Dialog.hpp
    //------------------------------------------------------------------
    #include "Widget.hpp"

    class Dialog : public Widget
    {
    vector<Widget*> widgets_;
    };
    //------------------------------------------------------------------
    Widget.hpp
    //------------------------------------------------------------------
    class Dialog;

    class Widget
    {
    Widget( Dialog* parent );
    };

    The problem is that whenever I try to declare Dialog variable compiler
    outputs that Dialog has incomplete type... Any suggestions?
     
    , Feb 15, 2007
    #1
    1. Advertising

  2. wrote:
    > I have 2 classes - Widget and Dialog. Dialog IS Widget. It contains
    > vector of Widgets. Widget get passed pointer to Dialog in constructor.
    > So both classes need to know about themselves.
    >
    > //------------------------------------------------------------------
    > Dialog.hpp
    > //------------------------------------------------------------------
    > #include "Widget.hpp"
    >
    > class Dialog : public Widget
    > {
    > vector<Widget*> widgets_;
    > };
    > //------------------------------------------------------------------
    > Widget.hpp
    > //------------------------------------------------------------------
    > class Dialog;
    >
    > class Widget
    > {
    > Widget( Dialog* parent );
    > };
    >
    > The problem is that whenever I try to declare Dialog variable compiler
    > outputs that Dialog has incomplete type... Any suggestions?


    In the code above there is nothing to suggest the behaviour you described.

    Try to ensure that 'Widget' class is defined before 'Dialog' class. You
    can do that by tweaking the order in which your headers are included.

    I also strongly recommend adding double inclusion guards to your headers.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Feb 15, 2007
    #2
    1. Advertising

  3. Guest

    On Feb 15, 7:58 pm, "Victor Bazarov" <> wrote:
    > wrote:
    > > I have 2 classes - Widget and Dialog. Dialog IS Widget. It contains
    > > vector of Widgets. Widget get passed pointer to Dialog in constructor.
    > > So both classes need to know about themselves.

    >
    > > //------------------------------------------------------------------
    > > Dialog.hpp
    > > //------------------------------------------------------------------
    > > #include "Widget.hpp"

    >
    > > class Dialog : public Widget
    > > {
    > > vector<Widget*> widgets_;
    > > };
    > > //------------------------------------------------------------------
    > > Widget.hpp
    > > //------------------------------------------------------------------
    > > class Dialog;

    >
    > > class Widget
    > > {
    > > Widget( Dialog* parent );
    > > };

    >
    > > The problem is that whenever I try to declare Dialog variable compiler
    > > outputs that Dialog has incomplete type... Any suggestions?

    >
    > In the code above there is nothing to suggest the behaviour you described.
    >
    > Try to ensure that 'Widget' class is defined before 'Dialog' class. You
    > can do that by tweaking the order in which your headers are included.
    >
    > I also strongly recommend adding double inclusion guards to your headers.
    >
    > V
    > --
    > Please remove capital 'A's when replying by e-mail
    > I do not respond to top-posted replies, please don't ask


    Thank you very much... I've found the mistake. You were right, the
    code was ok, but I have forgotten to include Dialog.hpp into main...
     
    , Feb 15, 2007
    #3
    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. DKP

    completing a link

    DKP, Jul 23, 2004, in forum: HTML
    Replies:
    2
    Views:
    393
  2. strotee76
    Replies:
    9
    Views:
    11,003
    Brian M. Dean
    May 8, 2005
  3. Peter A. Schott
    Replies:
    0
    Views:
    285
    Peter A. Schott
    Aug 23, 2005
  4. Saran
    Replies:
    0
    Views:
    282
    Saran
    Oct 18, 2006
  5. Ali Servet Dönmez
    Replies:
    16
    Views:
    519
    Ali Servet Dönmez
    Jul 6, 2008
Loading...

Share This Page