Is it possible to explicitly call a superclass constructor within a subclass?

Hi guys, Is it possible to call a superclass constructor within a subclass? If it is, how do you do it?
"superclass" and "subclass" are Java terms; in C++ we say parent/base class and derived class.

Yes, you can do it in the constructor initializer list:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
struct Base
{
    Base(int, int, int);
};
struct Derived
: Base
{
    int blah;
    Derived(int x, int y)
    : Base(1, x, 3) //here
    , blah(y)
    {
    }
};
Last edited on
Topic archived. No new replies allowed.