Questions tagged [constructor-inheritance]

For questions about Constructor Inheritance, the Object-Oriented Programming concept that constructors of a subclass must begin by invoking a constructor from the superclass.

In object-oriented programming languages, subclass construction typically must begin with the invocation of a constructor from the superclass.

In most languages, this can be done with the super keyword, or left as an implicit default constructor.

super(args);

However, to reduce the size of code, Java gives the option to instead call a different constructor from the same class, using the this keyword:

this(args, 1.5F);

See also:

6 questions
4
votes
5 answers

overriding parameterized constructors in sub-classes in java

i'm just beginning my story with Java, however I have some OOP experience with Python. I have the following class hierarchy : class A { public A() {}; public A(final java.util.Map dict) {}; } class B extends A { } public class Main { …
2
votes
1 answer

Trouble Understanding __init__() in subclass and super() function

I'm having a little trouble understanding these two particular concepts in Python. I feel like I get the gist of them, but don't understand them completely. From what I have gathered, super() calls the init method from the parent class and handles…
1
vote
0 answers

Inheriting protected constructor

As far as I understood, the using keyword can be used for inheriting constructors of a base class. In this code I'm trying to reuse the constructors of Base while making them public. Compilers say error : calling a protected constructor of class…
Newline
  • 769
  • 3
  • 12
1
vote
1 answer

How to inherit constructors out-of-line?

Is it possible to inherit constructors out-of-line in C++ so that they don't (say) get codegened in every translation unit? If so, how?
user541686
  • 205,094
  • 128
  • 528
  • 886
1
vote
2 answers

Constructor inheritance with classes of the same name

I want to inherit the constructor of the base class, but don't compile. How can I solve this problem without changing the class name? class MyClass { public: class A { }; }; class MyClass2 : MyClass { public: class A : MyClass::A …
0
votes
1 answer

Inherit constructors via using but make it out-of-line

Consider the following short but multifile example: // ************************** unit.h ************************** #pragma once #include struct S; struct B { B(int) {}; virtual ~B() {}; }; struct D : B { D(int); ~D()…
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71