Results 1 to 5 of 5

Thread: C++ method call

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2008
    Posts
    2
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: C++ method call

    You can not call virtual functions from constructor.
    Such behavior is undefined - your class instance is not constructed yet.

    Regards,
    Alex

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android
    Thanks
    62
    Thanked 260 Times in 246 Posts

    Default Re: C++ method call

    @Alex, it is not undefined behavior, only the "overriding" doesn't work.

    Overriding works only after the whole object is created because the objects are created from base class "down" - the base c-tor can't call a method in derived class since that slice of the object isn't created yet (or more correctly it's not yet initialized), so from c-tors and d-tor it's always the member function from the same class that gets called - so don't expect overriding.

  3. The following user says thank you to Zlatomir for this useful post:

    ^NyAw^ (21st November 2011)

Similar Threads

  1. None-GUI thread call widget method cause error
    By luochen601 in forum Qt Programming
    Replies: 3
    Last Post: 28th July 2010, 05:39
  2. Replies: 6
    Last Post: 15th April 2010, 20:02
  3. Signal/slot or direct method call within a class
    By mike_the_tv in forum Newbie
    Replies: 6
    Last Post: 11th March 2010, 18:49
  4. Replies: 0
    Last Post: 20th December 2009, 15:37
  5. Why can't I call base public method?
    By lni in forum Qt Programming
    Replies: 3
    Last Post: 13th April 2009, 20:37

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.