Tomas Bym schrieb:
> Hello, is there any way in FLTK or simply C++, how to get a pointer
> to some main class from in any place of the code.

Simply C++ is to use a static pointer or class - everywhere you include 
the static pointer/class it will be the same. A simple example:

Include file "s_data.h":
---------------------------------------------------
#ifndef s_data_h
#define s_data_h

struct data {
        int D1;
        int D2;
        data(): D1(0), D2(0) {}
};

class static_data
{
public:
        static data* Get_Data()         { return smp_Data; }
        static void Set_Data(data* D)   { smp_Data= D; }
private:
        static data* smp_Data;
};
#endif
---------------------------------------------------

usage for data class:
---------------------------------------------------
#include "s_data.h"

Class_With_Data_Member::Class_With_Data_Member()
{       // Set global data struct:
        static_data::Set_Data(&Member_Data);
}

data* static_data::smp_Data= 0; 
        // Definition of static member!
        // Usually inside "s_data.cpp"

---------------------------------------------------

Usage for other classes:
---------------------------------------------------
#include "s_data.h"

void some_class::Foo()
{
        if (data* ptr_Data= static_data::Get_Data())
        {       // Test for existing data
                if (ptr_Data->D1== 1) Do_Something();
                        // using data
        }
}
---------------------------------------------------

This is just written down, but should be good enough to show the 
principle. To find more sophisticated examples you should look for 
design pattern "singleton".
_______________________________________________
fltk mailing list
fltk@easysw.com
http://lists.easysw.com/mailman/listinfo/fltk

Reply via email to