Re: pointer problem: invoking the method of a pointer? (Solution)
Markus Pitha wrote:
Victor Bazarov wrote:
Put a breakpoint there, run it until it's stopped there, examine the
call stack. Get a book on Gtk and see how the signals work (there
has to be some explanation there, right?)
I have only some sophisticated text editor, not a whole c++
development environment, because I mostly work with java on eclipse.
I thought it's just a copy of the
pointer because I don't handle with addresses (&). So why does it
work to change the label in this way?
What *label*?
The label of the button. (first "0", then "1").
Ah... That's not a C++ question. It's a Gtk question.
What difference is it for you if I use a method of an object "Foo", an
object "FooFoo", or an object "Gtk::Button"?
I didn't talk about especially Gtk but about an object which is
accessed with any method.
You asked why it was important to define some 'menuClicked' or some
such member function so that its third argument would be *a pointer*
to a Button class, and not a reference. Apparently, it is important
to use a pointer so that the function could be made into *what seems
to be* a callback for Gtk messaging system. Why doesn't a reference
work? Most likely because Gtk was designed that way. Who here can
tell? It's off-topic.
Calling a member function of a class through a pointer to object
requires the -> operator, calling it through a reference to object
requires the . operator, that's the C++ requirement. It has nothing
to do with your problem, however.
struct Button {
void setLabel(const char*) { /* nothing */ }
};
void foo(int i, int j, Button* pButton) {
pButton->setLabel(" 1 "); // here we use a pointer
}
void foo(int i, int j, Button& rButton) {
rButton.setLabel(" 1 "); // here we use a reference
}
int main() {
Button button;
foo(0, 0, &button); // call the one that takes a pointer
foo(1, 1, button); // call the one that takes a reference
}
V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask