Hi,
I have a class called WaterTank which inherits from Depletable and Damagable.
Due to UE’s special no-custom-constructor rule, I have to use an init function. How, then, would I call the init functions in the base classes?
UWaterTank::UWaterTank()
{
}
UWaterTank::~UWaterTank()
{
}
void UWaterTank::init()
{
IDepletable.init(50);
IDamagable.init(100);
}
void UWaterTank::init(ULocation* loc)
{
IDepletable.init(50); // apparently, missing ; before .
IDamagable.init(100);
this->loc = loc;
}
ULocation* UWaterTank::getLocation()
{
return loc;
}
Not sure if it works with interfaces, but you can use ‘Super::FuncName()’ to pass execution to the virtual function in the superclass.
This code:
IDepletable.init(50);
IDamagable.init(100);
wouldn’t work in “regular” C++ either, because IDepletable and IDamagable are classes, not object instances. The correct way to invoke those superclass methods would be:
IDepletable::init(50);
IDamagable::init(100);
And as already mentioned, if you’re creating a UCLASS and inherit from a UObject type, then Unreal’s header tool will automatically generate a macro named “Super” that refers to the superclass name. This only works for single inheritance though and only when inheriting from UObjects. When using multiple inheritance with custom interface types as you are , the standard C++ way of calling superclass methods is required.