Re: [gtkmm] General C++ Design Question: relation of GUI toapplication



Paul Davis wrote:

> >  When I try to use this technique, I run into something that could be called
> >"static contagion".
>
>    [ ... ]
>
> >  So if I ever reach a line of code where I must use a static function, the me
> >thod of
> >
> >  writing classes with members that are pointers-to-classes seems to lead to a
> >lmost
> >
> >  everything being static.  Is there away to avoid this contagion?
>
> class Foo {
>       ...
>       gint callback ();
>
>       static gint _callback (void *arg) {
>           static_cast<Foo *>(arg)->callback ();
>       }
> };

Let me make sure I understand that:  Say we have a class Bar which contains a
member ,barsFooClass, that is pointer-to class Foo.

We find that we need to write a static function in class Bar which uses a function
of that member.

class Foo {

    gint non_static_thing;

    gint  fooFuction(int x) {
       return( x + gint non_static_thing);
    }

public:

    gint  _fooFunction(void *xclass, int x) {
         static_cast<Foo*>(xclass)->fooFunction(x);
    }

 };


 class Bar {

     static Foo  *barsFooClass;

     static int barFunction( int x, int  y) {

            return(  x +  Foo::_fooFunction(barsFooClass, y) );
     }

  };


  Foo *Bar::barsFooClass;

  int main() {

         Foo fooclass;
         Bar  barclass;

         fooclass.non_static_thing = 7;

         barclass.barsFooClass = &fooclass;
         ....
         gtk_timeout_add(1000, Bar::barFunction,...);

  }

--
Stephen Tashiro
tashiro trac wsmr army mil
tashiro zianet com
"Never let the task you are trying to accomplish
  distract you from the study of computers."






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]