object missing in reference to `Window::border'

This is a discussion on object missing in reference to `Window::border' within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm hoping this is a simple problem but I can't figure it out. I've looked around on Google and ...

  1. #1
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147

    object missing in reference to `Window::border'

    Hello,

    I'm hoping this is a simple problem but I can't figure it out. I've looked around on Google and found little helpful information.

    When compiling, I get this message: 'error: object missing in reference to `Window::border''

    The related (simplified) code is as follows:

    window.h
    Code:
    class Window
    {
        public:
            friend class WindowConfigListener;
    
        ...
    
        private:
            Image *border[9];
            ...
    };
    window.cpp
    Code:
    class WindowConfigListener : public ConfigListener
    {
        void optionChanged(const std::string &)
        {
            for(int i = 0; i < 9; i++)
            {
                Window::border[i]->setAlpha(config.getValue("guialpha", 0.8));
                ^ Fails here
            }
        }
    };
    I've looked around on google for a possible solution but was unable to find anything that was useful. I imagine there is a simple fix to this but the answer is eluding me.

    Thank you for your time in helping me with this problem.
    - Leeor

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    It looks like you are trying to set the border member variable of a Window object, but by treating it as if it were the member variable of a WindowConfigListener, which presumably is not a Window object.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    Well, that definitly gives me more insight. The next question is, how can I set a variable in a friend class? Or, is this just totally bad programming and instead go the route of creating a member function of Window that then gets called by the WindowConfigListener?

    Only problem then, is how can I get the WindowConfigListener Class to call a member function of Window without instantiating a new instance of class Window?

    Edit:
    You're right -- WindowConfigListener is not a Window class.
    - Leeor

  4. #4
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    I suppose a better question might be, how can I have a friend class set the value of a non-static member variable without creating a new Window object?
    - Leeor

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    how can I have a friend class set the value of a non-static member variable without creating a new Window object?
    It cannot do that. No object, no non-static member variables.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Quote Originally Posted by leeor_net View Post
    Only problem then, is how can I get the WindowConfigListener Class to call a member function of Window without instantiating a new instance of class Window?
    Pass a Window reference or pointer to the method, or to the constructor so you can reference it later.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,628
    Pass a Window reference or pointer to the method, or to the constructor so you can reference it later.
    Oh, good catch if indeed "new" implies "another".
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Professional Chef leeor_net's Avatar
    Join Date
    Apr 2004
    Location
    Charles Town, WV
    Posts
    147
    I found another solution that works well enough for me. In this case, the code is for a Window GUI Widget (based on GUIChan). Anyway, the WindowConfigListener 'listens' for changes to an option.

    As border is not a Static member of the Window class, I figured that it may not be necessary to explicitly modify that member and instead I could set a 'flag' that tells the Window class that there's been a change it needs to respond to.

    I added in a boolean variable, bool mGuiAlphaChanged. The rest of the code responds to that and the code is now working just fine... I'm not sure why I didn't think about this ahead of time but I thought I would post my solution so that others with a similar problem may see an alternative solution.

    Thank you all for your time and effort -- your help is very much appreciated.
    - Leeor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. PlaySound
    By cangel in forum C++ Programming
    Replies: 16
    Last Post: 10-08-2009, 05:29 PM
  2. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. C OpenGL Compiler Error?
    By Matt3000 in forum C Programming
    Replies: 12
    Last Post: 07-07-2006, 04:42 PM
  5. GCC - Strange networking functions error.
    By maththeorylvr in forum Windows Programming
    Replies: 3
    Last Post: 04-05-2005, 12:00 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21