Thread: forward declaration error?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    46

    forward declaration error?

    Code:
    class Bar;
    
    class Foo
    {
      public:
         Foo() { p_Bar = NULL;}
        ~Foo() {}
    
        void setBar(Bar *b) { p_Bar = b;}
        void doSomething()
        {
          std::cout<< "Hey I'm Foo and I'm doing something\n";
          notifyBar();
        }
      private:
        Bar *p_Bar;
        void notifyBar() {if (p_Bar != NULL) p_Bar->update();}
    
      protected:
    
    };
    
    
    class ControlFoo
    {
      public:
        ControlFoo() {}
        ~ControlFoo() {}
    
        void setFoo(Foo *f) {m_f = f;}
    
        void controlSomething() {m_f->doSomething();}
      private:
        Foo *m_f;
      protected:
    
    };
    
    
    class Bar
    {
      public:
        Bar() {}
        ~Bar() {}
        virtual void update() = 0;
        void setControlFoo(ControlFoo *cf) {m_cf = cf;}
      private:
    
      protected:
        ControlFoo *m_cf;
    };
    
    class BarBar: Bar
    {
      public:
        BarBar(): Bar() {}
        ~BarBar() {}
    
        virtual void update();
        void doBBSomething();
      private:
      protected:
    
    };
    
    void
    BarBar::update()
    {
      std::cout << "Hey! we got some update!\n";
    }
    
    void
    BarBar::doBBSomething()
    {
      m_cf->controlSomething();
    }
    The following example gives me the error
    t1.hpp: In member function ‘void Foo::notifyBar()’:
    t1.hpp:19: error: invalid use of incomplete type ‘struct Bar’
    t1.hpp:3: error: forward declaration of ‘struct Bar

    Can anyone help me understand this? Is this because Bar is not yet an complete type and the call in notifyBar requires it to be?

    Thanks!
    Last edited by sugarfree; 04-24-2010 at 11:21 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  3. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  4. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  5. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM