An off-topic question

Discussion in 'C++' started by Al-Burak, Nov 8, 2005.

  1. Al-Burak

    Al-Burak Guest

    I know that this is not a C++ question, but in the hope that some other
    programmer with GTKmm programming experience would come to this
    newsgroup, read my message and give me a hand on this issue I am
    posting the question here.I know that there is a mailing list for
    GTKmm, however, the list is very slow; to a point where one feel lucky
    to get a reply, what a shame.
    I am trying to write a class that derives from Gtk::VBox called
    Contacts; the idea is to pack every widget necessary to display and
    retrieve data from the user using a one class. This class will be
    passed to a Gtk::Notebook::append_page().
    The class compiles just fine, but at the point where I add the
    Gtk::HBox object to the Gtk::VBox derived class the program
    craches/segmentation fault.

    Could someone please tell me what I am doing wrong?

    Here is the example:
    ==========
    WinXP
    MinGW-GCC

    class Contacts : virtual public Gtk::VBox{
    protected:
    Gtk::HBox hbox1;
    Gtk::HBox hbox2;

    public:
    Contacts();
    virtual ~Contacts();
    }; //class
    jme::Contacts::Contacts(){
    this->pack_start(hbox1); //Segmentation Fault
    }
    ==============

    TIA
     
    Al-Burak, Nov 8, 2005
    #1
    1. Advertising

  2. Al-Burak

    Guest

    >this->pack_start(hbox1); //Segmentation Fault

    aren't you calling pack_start on this object before "this" is
    completely constructed?

    G
     
    , Nov 8, 2005
    #2
    1. Advertising

  3. Al-Burak

    mlimber Guest

    wrote:
    > >this->pack_start(hbox1); //Segmentation Fault

    >
    > aren't you calling pack_start on this object before "this" is
    > completely constructed?


    Yes and no. The OP's code was:

    class Contacts : virtual public Gtk::VBox{
    protected:
    Gtk::HBox hbox1;
    Gtk::HBox hbox2;

    public:
    Contacts();
    virtual ~Contacts();
    }; //class

    jme::Contacts::Contacts(){
    this->pack_start(hbox1); //Segmentation Fault
    }

    At the point of the segfault, all of the bases and members of Contacts
    are constructed and [this] points to the current object, so there
    should be no problem using data members (e.g., hbox1) or a member
    function or base-class' function (e.g. pack_start). The exception is if
    pack_start() is a virtual function that is actually over-ridden by
    Contacts (which is not shown in the OP). See this FAQ:
    http://www.parashift.com/c -faq-lite/strange-inheritance.html#faq-23.5
    ..

    Also, the use of [this] seems to be unnecessary in the constructor
    unless there's some funny business going on that is not evident from
    the OP. The body would likely be the same if it read:

    pack_start( hbox1 );

    Cheers! --M
     
    mlimber, Nov 8, 2005
    #3
  4. Al-Burak wrote:
    > I know that this is not a C++ question, but in the hope that some other
    > programmer with GTKmm programming experience would come to this
    > newsgroup, read my message and give me a hand on this issue I am
    > posting the question here. I know that there is a mailing list for
    > GTKmm, however, the list is very slow; to a point where one feel lucky
    > to get a reply, what a shame.


    Only this time. We'll check you from now on.

    > I am trying to write a class that derives from Gtk::VBox called
    > Contacts; the idea is to pack every widget necessary to display and
    > retrieve data from the user using a one class. This class will be
    > passed to a Gtk::Notebook::append_page().
    > The class compiles just fine, but at the point where I add the
    > Gtk::HBox object to the Gtk::VBox derived class the program
    > craches/segmentation fault.
    >
    > Could someone please tell me what I am doing wrong?
    >
    > Here is the example:
    > ==========
    > WinXP
    > MinGW-GCC
    >
    > class Contacts : virtual public Gtk::VBox{
    > protected:
    > Gtk::HBox hbox1;
    > Gtk::HBox hbox2;
    >
    > public:
    > Contacts();
    > virtual ~Contacts();
    > }; //class
    > jme::Contacts::Contacts(){
    > this->pack_start(hbox1); //Segmentation Fault
    > }
    > ==============


    This could be anything. Make sure (I don't know gtk) you are using the
    library correctly, check the arguments you are passing, check your
    inheritance, etc. Perhaps something is going wrong in the HBox
    constructors, or in the base class.

    If this appears to be correct, make sure memory allocations are done
    correctly. How do you create Contacts objects? On the heap? If so, are
    they correctly created/used/deleted?

    I hope it's a stupid error with the library. If not, you'll probably
    need a couple of days to solve the problem because this looks like
    undefined behavior.

    Good luck!


    Jonathan
     
    Jonathan Mcdougall, Nov 8, 2005
    #4
  5. Al-Burak

    Guest

    [snip[
    > The class compiles just fine, but at the point where I add the
    > Gtk::HBox object to the Gtk::VBox derived class the program
    > craches/segmentation fault.

    [snip]

    A debugger can give you more information about a crash, such as a
    backtrace. valgrind's memcheck is also very useful.

    Murray
     
    , Nov 10, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. steve

    Re: ~~Off Topic Question

    steve, Jul 9, 2003, in forum: HTML
    Replies:
    3
    Views:
    374
    Found Lacking
    Jul 9, 2003
  2. Mr. Clean

    Re: ~~Off Topic Question

    Mr. Clean, Jul 9, 2003, in forum: HTML
    Replies:
    4
    Views:
    448
    Sid Ismail
    Jul 10, 2003
  3. Found Lacking

    Re: ~~Off Topic Question

    Found Lacking, Jul 10, 2003, in forum: HTML
    Replies:
    2
    Views:
    347
    Found Lacking
    Jul 10, 2003
  4. Wayne...
    Replies:
    15
    Views:
    787
    Toby Inkster
    Jul 23, 2004
  5. jacob navia
    Replies:
    5
    Views:
    559
    spinoza1111
    May 30, 2010
Loading...

Share This Page