Do we need constructors in an inheriting class?

K

K Viltersten

I have:

abstract class Vehicle
{
public Vehicle (int i) {...}
abstract public void doMove ();
}

When i write the following:

class Car: Vehicle

magic happens and by pressing a key
combo, VS asks me if i want to extend
the abstract class.

I say, YES! And there it is - a stub
of a function already with "override"
and "throw this and that".

However, no constructor(s) is/are
created for me. Does it mean i need
not to implement those? In C++ i
needed to provide my own and make
them call the super class...
 
B

Ben Voigt [C++ MVP]

However, no constructor(s) is/are
created for me. Does it mean i need
not to implement those? In C++ i
needed to provide my own and make
them call the super class...

If you want the same set of constructors... but often a derived class will
require additional parameters or supply defaults, so there's really no way
for the IDE to create the constructors automatically.
 
K

K Viltersten

However, no constructor(s) is/are
If you want the same set of constructors...
but often a derived class will require
additional parameters or supply defaults,
so there's really no way for the IDE to
create the constructors automatically.

Informative remark. Didn't think of it.
Thank you.
 
A

Arne Vajhøj

Ben said:
If you want the same set of constructors... but often a derived class will
require additional parameters or supply defaults, so there's really no way
for the IDE to create the constructors automatically.

There should be an option to generate constructors with same arguments
as the super class.

There is a decent chance that is what is needed.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top