Re: C++-classes.



On Fri, 2002-10-18 at 10:55, Peeter Vois wrote:
On 18 Oct 2002 09:35:06 +0100
James Durie <jdurie anvil co uk> wrote:

You can't pass a method in as a callback function pointer. There is a
hidden parameter, this, to all methods which points to the instance of
the class.

Instead try:
gtk_signal_connect(GTK_OBJECT(button), "clicked",
GTK_SIGNAL_FUNC(clicked_cb), this);


I would like to say that I never used GTK with C++ before but does not following
work? Or something like this:

gtk_signal_connect(GTK_OBJECT(button), "clicked",
      GTK_SIGNAL_FUNC(this->Test), NULL);


That would imply that a separate instance of each method of the class is
created whenever an instance of the class is created. Which would be
incredibly wasteful of memory. Instead a single instance of each method
is created and a hidden parameter is passed to the method whenever it is
called. C++ hides the details of this from you.

So passing the address of method Test as a function pointer would not
work because the method would have no idea which instance of the class
it is working on.

James

-- 
James Durie               Phone:  +44 20 7749 7904
Anvil Software Limited    Fax:    +44 20 7749 7916
46-48 Rivington Street    e-mail: jdurie anvil co uk
London EC2A 3QP




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