[C++]Use Glib::RefPtr<> with my own classes ?
- From: Aurélien Ansel <camumus gmail com>
- To: gtkmm-list gnome org
- Subject: [C++]Use Glib::RefPtr<> with my own classes ?
- Date: Fri, 30 Jul 2010 18:21:04 +0200
Hi everyone,
my english is not perfect, sorry in advance for that.
I try to use Glib::RefPtr<> with my own classes.
I have seen in the docs that Glib::RefPtr is the smart pointers for the Glib::Object subclasses, subclasses that wraps C functionalities of the Glib, is it ?
I have developped my main class in order to subclass it with my other classes :
class Referencable
{
public:
void reference();
void unreference();
protected:
Referencable():_ref_counter(1) {}
virtual ~Referencable() {}
private:
unsigned long long _ref_counter;
};
the 2 main methods :
void Referencable::reference() {
++_ref_counter;
}
void Referencable::unreference() {
--_ref_counter;
if (_ref_counter == 0)
delete this;
}
I have tested it, that seems to work, but after developped many subclasses with it, i had some problems with invalids Glib::RefPtr that are destroyed "too soon".
My questions are : is it possible to use Glib::RefPtr<> with classes that aren't from Glib C ?
If yes, someone have an idea what is wrong with my code ?
Thanksfully,
Aurelien
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]