Thread: class problem

  1. #1
    Registered User
    Join Date
    Jan 2007
    Posts
    54

    class problem

    say i have this class with two pointers to objects of other classes as it's members

    Code:
    class cLoginManager
    {
    public:
    	cLoginManager();
    	~cLoginManager();
    	
    	cInformationWindow* InformationWindow;
    	cLoginWindow* LoginWindow;
    
    };
    then i have

    Code:
    
    class cInformationWindow
    {
    public:
    	cInformationWindow();
    	~cInformationWindow();
    
            bool getVisible(){return m_Visible;};
            bool m_Visible;
    
    };
    and

    Code:
    
    class cLoginWindow
    {
    public:
    	cLoginWindow();
    	~cLoginWindow();
    
    
            void ControlClick(int id)
            {
                    //here i want to be able to access the cInformationWindow's getVisible()
            };
    
    
    };

    I am not sure how i can access the the cInformationWindow's getVisible() function from inside cLoginWindow::ControlClick(int id)

    I could do it by delcaring a pointer to the cWindowManager class and then extern the pointer at the top of the file holding the declaractions of the cLoginWindow class and then in the cLoginWindow::ControlClick(int id) access the getVisible() using the pointer.

    Though i dont really want to do that as that requires the class to know of an object inorder to be useable.

    So is there a way for the cLoginWindow, which is a member of cWindowManager to access the function of another member of cWindowManager?

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    I'm kind of confused. Do you want the value from a specific instance of cInformationWindow? Or do you want to inherit the functionality of cInformationWindow within cLoginWindow? If the latter change

    class cLoginWindow

    to

    class cLoginWindow : public cInformationWindow

    and within ControlClick just test the bool or use the function as (loosely) the two classes are now merged together.

    http://www.cprogramming.com/tutorial/lesson20.html

    If it's the former use the . operator to execute the getVisible method from an instance of the first class.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> If it's the former use the . operator to execute the getVisible method from an instance of the first class.

    If this is what you want, then pass a pointer or reference to the InformationWindow member variable to the ControlClick function, then call the getVisible() function from it.

  4. #4
    Registered User
    Join Date
    Jan 2007
    Posts
    54
    i do not want to use inheritance

    i want to do the first option

    But this does not work:

    What is it I am doing wrong?

    Code:
    class cLoginManager;
    
    class cLoginWindow
    {
    public:
    	cLoginWindow();
    	~cLoginWindow();
    
    
            void ControlClick(int id)
            {
                    cLoginManager.InformationWindow.getVisible()
            };
    
    
    };

  5. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by e66n06 View Post
    Though i dont really want to do that as that requires the class to know of an object inorder to be useable.

    So is there a way for the cLoginWindow, which is a member of cWindowManager to access the function of another member of cWindowManager?
    You're asking how an object can operate on some other object it knows nothing about? Answer is "It can't."

  6. #6
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    cLoginManager is a type. Until you make an instance of cLoginManager you won't get anything useful out of it -

    cLoginManager thing;
    thing.cInformationWindow.getVisible();

    Or
    Code:
    class cLoginWindow
    {
    cLoginManager thing;
    public:
    	cLoginWindow();
    	~cLoginWindow();
    
    
            void ControlClick(int id)
            {
                    thing.InformationWindow.getVisible();
            };
    
    
    };
    or
    Code:
    class cLoginWindow
    {
    public:
    	cLoginWindow();
    	~cLoginWindow();
    
    
            void ControlClick(int id, cLoginManager &thing)
            {
                    thing.InformationWindow.getVisible();
            };
    
    
    };
    should work

  7. #7
    Registered User
    Join Date
    Jan 2007
    Posts
    54
    but i want the object of the cLoginWindow class that was declared as a memeber of the cLoginManager object to be able to find out if the object of the cInformationManager class that was also declared as a memeber of the cLoginManager class is visible or not...

    surely the "thing" object will not be the same as the instance of the cLoginManager object's member "InformationWindow"...

    or am i wrong?

  8. #8
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> or am i wrong?
    Look at the second example. The function takes a cLoginManager as an argument. Just pass the LoginWindow from your LoginManager class to the function.

  9. #9
    Registered User
    Join Date
    Jan 2007
    Posts
    54
    ok, i will give that a go thanks everyone

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Mesh Class Design problem
    By sarah22 in forum Game Programming
    Replies: 2
    Last Post: 05-20-2009, 04:52 AM
  2. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  3. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  4. My Window Class
    By Epo in forum Game Programming
    Replies: 2
    Last Post: 07-10-2005, 02:33 PM
  5. Replies: 3
    Last Post: 12-03-2001, 01:45 PM