RE: [gtkmm] Glib::RefPtr<foo>->instance?



> From: Dale Wiles [mailto:dwiles Buffalo Veridian Com] 
>   I've been going a few rounds with Glib::RefPtr<>s and could use
> some help.
> 
>   What is the "proper" way to access the underlying instance (foo *)
> of a Glib::RefPtr<foo>?

So far nobody has needed to. RefPtr does not implement operator* so that you
don't use it when you shouldn't.

>   For example: If I want to test to see if 2 RefPtrs refer to the
> same class, I can use a == b.  How do I test to see if 2 separate
> classes have the same value?  In pointer terms I'd use *a == *b.

That would need the underlying class to implement operator==(). Can you give
us an example of a class that's used via RefPtr that implements operator==()
?

>   I know I can add a member function to foo which hands itself back.
> Something like "foo *self() { return this; }".  Then I can use
> *(a->self()) == *(b->self()).  Is this the "right" way?
> 
>   The underlying instance is also necessary when calling an external
> library that wants a pointer to a instance and doesn't understand
> Glib::RefPtr<>s.

But *refPtr would give you a pointer to the C++ instance. If an external
library wants a pointer to a C++ instance for a gtkmm class that is used via
RefPtr then that external library has an incorrect API. It should take a
const RefPtr<>&.

If you are talking about a C instance, then you need refPtr->gobj().

Murray Cumming
murrayc usa net
www.murrayc.com 



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