Re:



You can also use std::tr1::shared_ptr. This not (yet) standard C++ but is present in most compilers (gcc 4, visual studio 2008 and 2010…).

When C++0x is released, you'll just have to replace "std::tr1" with "std::".

yann

On 28/01/11 15:19, Culpian Camilo Martin wrote:
El vie, 28-01-2011 a las 15:11 +0100, Krzesimir Nowak escribió:
2011/1/28 Culpian Camilo Martin<camiloculpian gmail com>:
El vie, 28-01-2011 a las 14:46 +0100, Krzesimir Nowak escribió:
2011/1/28 Culpian Camilo Martin<camiloculpian gmail com>:
ok, i'll try it, i have had some troubles doing this:

class foo
{
        static ref_ptr<foo>  create
        (
                return ref_ptr<foo>(new foo());
        );
        foo();
        ~foo();
        ref_ptr<foo>  set_something()
        {
                //set something

                return ref_ptr<foo>(this);
                //for using foo->set_something()->set_something();
                // oviously the ref_ptr delete "this", and cause a segfault
                // any idea how can avoid this?
        }
}

Would be good to show what is this ref_ptr class...

If the below code segfaults then maybe copy constructor of ref_ptr
does not increment reference count.

ref_ptr<foo>  f = foo::create();
f->set_something()->set_something();

the problem is not when i do this:

ref_ptr<foo>  f = foo::create();
f->set_something()->set_something();

the problem is when i do this:

class foo_b : public foo
{
        static ref_ptr<foo_b>  create()
        {
                return ref_ptr<foo_b>(new foo_b());
        }
        foo_b();
        ~foo_b();
}

when i do:

foo_b foob = foo_b::create();
foob->set_something(); //here ref_ptr delete the object member class
foo... this is what i can't do right.

Now I see. An option would be:
1. returning void instead of ref_ptr to this.
2. coding the reference count inside foo_b, instead of in ref_ptr.

I would opt for first solution.
yes, but if i extend from Glib::Object, and i use Glib::RefPtr, wouldn't
be a better and elegant solution? or it is not possible?

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list


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