5

What's the fuckin point when a language makes you call the constructor of a parent class in the child class before you can use the inherited items?

Why do I need to call `super()` every time in my constructors? Why can't this be automatic?

Comments
  • 2
    It can be, but only when assuming the parent doesn't need any parameters to be constructed. Languages like java and c# and sometimes js does that.

    Otherwise the computer will do it's job and complain about the id10t not filling in the values.
  • 0
    @melezorus34 I prefer the c++ way of doing things
  • 0
    The point is, u could wish redefine conductor entirely
    Up to u of u need parent constructor or not

    Don't redefine constructor in child, if u don't wish to face this problem
  • 1
    @darkwind I see a typo, I go choo choo
  • 0
    Because of the concept of encapsulation.
    The super class might not be in a valid state until you call it's constructor
  • 0
    It IS automatic when you write no new constructor.

    C## has nice syntax for it though. It can be quite elegant in some languages.

    public void MyConstructor (val) : base (val)
  • 0
    @Inxentas C##, oh my god. I'm just gonna use fire.
Add Comment