Thread: Complicated but urgent!

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    132

    Complicated but urgent!

    Ok, I will try to explain things as best as I can. I have a 'base' class called CRTBase. This class is pretty simple, it contains just a member function Update which takes as parameter a pointer to the CWindowFrame class.
    Code:
    void Update (CWindowFrame *window);
    There is a protected member called win, type of wnWindowStruct.
    My code here is simple. the CWindowFrame class has an instance to a struct called wnWindowStruct.

    so, here is my code for the Update method:
    Code:
    void Update(CWindowFrame *window)
    {
       ZeroMemory(&win,sizeof(wnWindowStruct));
       win = window->GetWindowStruct();
       //GetWindowStruct() returns the instance of the struct used
      //in the CWindowFrame, which's contents will change on the fly.
     //So this struct needs to be updated in every frame.
    }
    Now, Lets say i have another class, which inherits from the CRTBase:
    Code:
    class CRTCamera : protected CRTBase
    {
       ...functions here
    
    };
    What I need to do is have access to the protected member 'win' of the base class. Which I do have. The problem is that the contents of the wnWindowStruct win, are empty! I use the Update(&window) after creating and registrating the main window. For example, the width member of the 'win' variable must be 640. but it is 0.

    Any ideas?
    Thanks a lot
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    sounds like your using inharitance(forgive my spelling)

    If that is true, then you need to creat a virtual method to access "win".
    I'm not sure but hope that helps.
    maybe if you could explain a little more.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Of course I am using inheritance, it is obvious here.

    My class definition for CRTBase is:
    class CRTBase
    {
    public:
    void Update(CWindowFrame *window);

    protected:
    wnWindowStruct win;

    };

    You suggest that I make the protected variable virtual?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Complicated but urgent!
    Don't mark your threads as Urgent.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  5. #5
    Registered User
    Join Date
    Oct 2002
    Posts
    21
    >>You suggest that I make the protected variable virtual?
    i don't think you can make a variable virtual


    if win is in your base class then do something like
    Code:
    wnWindowStruct virtual getWin();
    bool virtual setWin(wnWindowStruct w);
    just use some member access functions
    (please forgive my terminology. I am not sure if that is the correct term)
    to set your variable

  6. #6
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Sorry for the 'urgent' text in my topic.

    This is what I am trying to avoid. You see, I am having about 3 classes that need to update their private win structure. That way, I should call 3 times the member function called Update of each class to update the win structure to the current one, the one in the CWindowFrame. So, I thought that it would be nice if I only updated the base class 'win' structure and all the other classes used this one. Isnt it a good idea? But I am stuck here.
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  7. #7
    Wouldn't it just work if you created a VIRTUAL Update(); function for your classes?

    Code:
    virtual void Update(CWindowFrame *window);
    This should call the Base class UPDATE fxn and not an instance of UPDATE() in the current class.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  8. #8
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    No, this wont do. I'd better just let every class have an Update function. What I want is that every class, such as Camera for example, to have access to that 'win' structure in CRTBase. Update function will accept a CWindowFrame parameter and set the win = parameter->GetWindowStruct();

    This should be done every frame. Then, the camera for example class can use the updated 'win' to retrieve information out of it. My problem is that win is no initialized correctly and it contains nothing in it. When I test the win values inside the Update function of the CRTBase class, it works ok. But when I test it from a class that inherits the CRTBase class, it doesnt. What might it be?
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  9. #9
    No, this wont do. I'd better just let every class have an Update function.
    Every class already has an Update() fxn if it has inherited from CRT class, that's inheritance, you need to declare that fxn to be VIRTUAL in order to call the BASE class Update() fxn.

    When you inherit you are just passing the structure, variables and functions but the variables are empty and the functions refer to the current class. You need to declare the function VIRTUAL in order for the Update() fxn in the BASE class to be called from the SUB class.
    My Avatar says: "Stay in School"

    Rocco is the Boy!
    "SHUT YOUR LIPS..."

  10. #10
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    urgent? urgent for who? the only thing urgent for me in the next 10 hours is sleep.
    hello, internet!

  11. #11
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    Ok, thanks onestiffrod, I will try that.

    moi, it is urgent for me, not for you
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

  12. #12
    Registered User
    Join Date
    Jun 2002
    Posts
    132
    It worked! Thanks a lot.
    Y3K Network http://www.y3knetwork.com
    Bringing the software of the future on the net.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Minimax, URGENT :(
    By Dark-MX0Z in forum C++ Programming
    Replies: 6
    Last Post: 11-14-2007, 06:29 AM
  2. pls help me urgent..
    By intruder in forum C Programming
    Replies: 4
    Last Post: 01-13-2003, 04:41 AM
  3. text box & buttons on window .. pls help urgent ???
    By intruder in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2002, 10:28 PM
  4. Help.... Urgent... Thanks!
    By weihann in forum C Programming
    Replies: 0
    Last Post: 02-27-2002, 10:15 PM