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...
--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy
Peter Duniho - 20 Mar 2008 21:41 GMT
> [...]
> 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...
Again, I think "just try it" is useful advice here.
But, no...just because the constructors weren't implemented for you, that
doesn't mean you don't have to implement them. The "extend the abstract
class" applies only to the abstract members. The constructor in the
abstract class isn't itself abstract (nor could it be), and so wouldn't
show up as part of the auto-generated members in your derived class.
If the abstract class had defined a constructor with no parameters, then
you could get away with not defining any new constructors for the derived
class. But it doesn't, so you can't (and in fact, you'll be required to
call the base constructor when declaring your derived constructor).
Pete
Ben Voigt [C++ MVP] - 21 Mar 2008 18:47 GMT
> 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 Viltersten - 21 Mar 2008 23:57 GMT
>> However, no constructor(s) is/are
>> created for me. Does it mean i need
[quoted text clipped - 7 lines]
> so there's really no way for the IDE to
> create the constructors automatically.
Informative remark. Didn't think of it.
Thank you.
--
Regards
Konrad Viltersten
--------------------------------
sleep - a substitute for coffee for the poor
ambition - lack of sense to be lazy
Arne Vajhøj - 30 Mar 2008 01:03 GMT
>> However, no constructor(s) is/are
>> created for me. Does it mean i need
[quoted text clipped - 5 lines]
> 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