Reputation: 14379
I have a base class (header):
class BaseClass
{
public:
BaseClass(int); // note no default constructor.
}
and a class that derives it:
class DerivedClass : public BaseClass
{
public:
DerivedClass(void);
}
DerivedClass::DerivedClass (void) // note SPECIFICALLY no parameters.
{
super (10); // equivalent of what I am trying to do in Java (I think)
}
How do I call the constructor of the inherited class in my derived class?
Upvotes: 2
Views: 75
Reputation: 599
class BaseClass
{
public:
BaseClass(int) {};
} ;
class DerivedClass : public BaseClass
{
public:
DerivedClass(void);
};
DerivedClass::DerivedClass (void)
:BaseClass(10)
{
}
Upvotes: 1
Reputation: 2838
This is what you want:
DerivedClass(void):BaseClass(10) {
//blah blah blah
}
Upvotes: 0
Reputation: 33655
like this:
DerivedClass::DerivedClass (void) : BaseClass(10)
{ }
NOTE: if you are unfamiliar with the syntax, look out for member initialization list.
Upvotes: 1