mardi 18 avril 2017

using an instance of a class in another class

I need calling methods and using other fields of an instance of a class inside another class. when I call another class's method, fields of calling class returns to their initial value. An examle of what I am doing:

class MainView
{
    // ...
    bShowToolbarHoriz=false;
    toolbar.Destroy()
    toolbar.Create()
}

extern MainView mainview;

class Toolbar
{
    // ...
    Destroy() { /* ... */ }
    Create()
    {
        // here bShowToolbarHoriz value is true
        // ??? 
        if (mainview.bShowToolbarHoriz)
        {
            // create toolbar horizontally 
        }
        else
        {
            // create toolbar vertically
        }
    }

extern Toolbar toolbar;

I know I'm doing it wrong way, maybe I should make my fields private and send them to functions as argument. but what should I do about methods? and what is the reason of this behavior?






Comments
0 Comments

0 commentaires:

Enregistrer un commentaire