Important: Please read the Qt Code of Conduct -

Passing this into constructors for child classes

  • 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?


  • Moderators


    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.

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

    Note the "new"

  • Moderators

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

Log in to reply