MQL5Book/Scripts/p3/FinalDelete.mq5
super.admin 1c8e83ce31 convert
2025-05-30 16:09:41 +02:00

56 lines
1.7 KiB
MQL5

//+------------------------------------------------------------------+
//| FinalDelete.mq5 |
//| Copyright 2021, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Base stub |
//+------------------------------------------------------------------+
class Base
{
public:
void method() { Print(__FUNCSIG__); }
};
//+------------------------------------------------------------------+
//| Derived stub |
//+------------------------------------------------------------------+
class Derived final : public Base
{
public:
void method() = delete;
void derivedMethod() { Print(__FUNCSIG__); }
};
/*
// ERROR:
// cannot inherit from 'Derived' as it has been declared as 'final'
class Concrete : public Derived
{
};
*/
//+------------------------------------------------------------------+
//| Script program start function |
//+------------------------------------------------------------------+
void OnStart()
{
Base *b;
Derived d;
b = &d;
b.method();
((Derived *)b).derivedMethod(); // explicit typecasting in-place
/*
// ERROR:
// attempting to reference deleted function 'void Derived::method()'
// function 'void Derived::method()' was explicitly deleted
((Derived *)b).method();
d.method();
*/
}
//+------------------------------------------------------------------+