PR and technical info for developers
Have you ever designed an abstract class in ZScript? If so, you've probably written code that looks like this:
Code: Select all
class MyAbstractClass abstract
{
virtual void MyFunc()
{
}
virtual int MySecondFunc()
{
return 0;
}
virtual bool MyThirdFunc()
{
return false;
}
}Code: Select all
class MyAbstractClass abstract
{
virtual void MyFunc()
{
ThrowAbortException("%s: Must override MyFunc.", GetClassName());
}
virtual int MySecondFunc()
{
ThrowAbortException("%s: Must override MySecondFunc.", GetClassName());
return 0;
}
virtual bool MyThirdFunc()
{
ThrowAbortException("%s: Must override MyThirdFunc.", GetClassName());
return false;
}
}But soon, not anymore.
Enter abstract functions.
What is an abstract function? Well, programmers already know, of course. But let me explain for those who are new to programming languages. Assuming you know what a virtual function is, an abstract function is just a virtual function without any code:
Code: Select all
class MyAbstractClass abstract
{
abstract void MyFunc();
abstract int MySecondFunc();
abstract bool MyThirdFunc();
}- Must be defined in an abstract class.
- Any non-abstract subclass must override them.
