Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing this into constructors for child classes
Qt 6.11 is out! See what's new in the release blog

Passing this into constructors for child classes

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 1.6k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • X Offline
    X Offline
    XtrmJosh
    wrote on last edited by
    #1

    Hi all,

    I'm looking to pass a pointer in to a constructor, to the class I'm instantiating it from. Something like this:

    @Util::Util(Core * coar)
    {
    core = coar;
    }@

    Problem is I keep getting segmentation faults when I do this. I think it may be related to the way I'm instantiating, since I had to set fpermissive in order to run this code:

    @Util * util = Util(this);@

    Can someone advise why I get this segfault and how I can either work around or fix the issue?

    Thanks

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      Hi,

      If you need fpermissive to compile, that means your code doesn't conform to the C++ standard.

      We'll need more error messages and more code to be able to see what the issue is.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • mranger90M Offline
        mranger90M Offline
        mranger90
        wrote on last edited by
        #3

        I think what you need to do is:
        @
        Util * util = new Util(this);
        @

        Note the "new"

        1 Reply Last reply
        0
        • JKSHJ Offline
          JKSHJ Offline
          JKSH
          Moderators
          wrote on last edited by
          #4

          [quote author="mranger90" date="1388151847"]Note the "new"[/quote]Ah... that's it. Can't believe I didn't see that :D

          Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved