dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2017
    Posts
    9

    Overriding the constructor

    Hi All,
    Just wanted to know in what scenario we need to override the constructor in python?
    And how to do that?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,748

    Re: Overriding the constructor

    As in define a constructor in a derived class, perhaps one that invokes a base class constructor?

    I'm curious what prompted this question, i.e., what made you ask this question?
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    Join Date
    Mar 2017
    Posts
    9

    Re: Overriding the constructor

    Yes I was also surprised. In one interview it was asked how to override a constructor. Then it came to my mind what scenario this would be useful to override the constructor.
    Last edited by Rajesh78; May 22nd, 2018 at 04:55 AM.

  4. #4
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,748

    Re: Overriding the constructor

    Well, then the answer should be fairly obvious: when your derived class objects need to be initialised in a way not anticipated by the base class. I'm sure you have come across such cases in other programming languages that also have native OO support.

    As for the how: do you know how to write a constructor? Do you know how to use super to invoke a base class method? If not, learn how. If you do, then you have your answer.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  5. #5
    Join Date
    Mar 2017
    Posts
    9

    Re: Overriding the constructor

    Thanks Laserlight..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)