Pointer vs. reference
- From: Surya Kiran Gullapalli <skg fluent co in>
- To: gtkmm-list <gtkmm-list gnome org>
- Subject: Pointer vs. reference
- Date: Wed, 23 Feb 2005 13:32:03 +0530
Hi,
I'm writing a small application, which should display a window with an image in it, with out window borders (similar to splash window).
I'm trying to add image to the window using add () function
here pix is const Glib::RefPtr<Gdk::Pixbuf>&
=============
Gtk::Image *image = new Gtk::Image (pix) ;
add (*image) ;
image->show() ;
=============
This works fine. But the memory allocated to image is lost. I've to retrieve it.
So i've done like this
=============
Gtk::Image image (pix) ;
add (image) ;
image.show() ;
=============
But when i do this, the image is not visible. (Reason could be , after the function, image will be out of scope and will be destroyed, as its not a pointer
The same thing happens, if i use auto_ptr also
=============
std::auto_ptr<Gtk::Image> image (new Gtk::Image (pix))
add (*image) ;
image->show() ;
=============
what am i doing wrong. Its very much possible, that i'm doing a very silly mistake, or i must have not understood the basics of c/c++ well.
If i use pointer, how to free the memory allocated to it.
Thx,
Surya
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]