Well, STL is not a one-size-fits-all solution. You have to pay much attention to specifics here.
You're confusing soft with warm. It's not a question of STL. I'll figure it out there myself... (if someone doesn't have it, it doesn't mean that it can't be done in principle)
The easiest way to implement all the possible functionality with abstract methods in a base class or interface, and in the descendants - either implementation or =delte. In this case, you need to pass pointers or references of the same type to the methods of the base class. Although there is an unavoidable evil in the form of a virtual table, but it's better to arrange the architecture in such a way that there is no expensive branching via dynamic_cast anywhere.
The bug is in the priorities of calling reloaded functions when an implicit type conversion is performed for a pointer/class parameter. In C++ all is OK, but in MQL the compilation error"ambiguous call to overloaded function" One of the workaround variants is suggested above, but it is large and not convenient, and I have no desire to use it for a dozen of similar functions. Perhaps there is something simpler?
Bug MT5(build 2323), Inside a template function, a passed pointer within an explicit type conversion behaves like a class, causing a compile-time error accordingly:
#define PRINT(x) ; Print(#x, ":", string(x))
template<typename T>
class ClassWrapper{
public:
T data;
};
class ClassA{};
class ClassB : public ClassA{};
template<typename T, typename TT>
void func(const T &_wrapper, const TT &value){
T wrapper = _wrapper;
PRINT(typename(wrapper.data)); // Ok: ClassA*
PRINT(typename(value)); // Ok: ClassA*
PRINT(typename(TT)); // Ok: ClassA*//wrapper.data = (TT)(value); // Compiler Error: 'value' - object required //wrapper.data = (TT)(wrapper.data); // Compiler Error: 'data' - object required
ClassB b;
PRINT(typename((TT)(b))); // Result: C lassA. During explicit type conversion, TT is "ClassA" instead of "ClassA*"
};
voidOnStart(){
ClassWrapper<ClassA*> a_ptr_wrapper;
ClassA a;
const ClassA* a_ptr = &a;
func(a_ptr_wrapper, a_ptr);
};
bool CheckTradingPermission()
{
//--- Для режима реального времениif(IsRealtime())
{
//--- Проверка соединения с серверомif(!TerminalInfoInteger(TERMINAL_CONNECTED))
return(false);
//--- Разрешение на торговлю на уровне данной запущенной программыif(!MQLInfoInteger(MQL_TRADE_ALLOWED))
return(false);
//--- Разрешение на торговлю на уровне терминалаif(!TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
return(false);
//--- Разрешение на торговлю для текущего счетаif(!AccountInfoInteger(ACCOUNT_TRADE_ALLOWED))
return(false);
//--- Разрешение на автоматическую торговлю для текущего счетаif(!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))
return(false);
}
//---return(true);
}
Опубликовал статью ZigZag всему голова (Часть II): Примеры получения, обработки и отображения данных В первой части был описан модифицированный индикатор ZigZag и класс для получения данных индикаторов такого типа. Теперь мы покажем как создать индикаторы на основе этих инструментов, а также напишем эксперта для тестов, который будет заключать...
Bug MT5(build 2323), the same template object B<int> can be created after object of class B<void*>, but if done before, a compilation error occurs. Probably the reason is the work of template class generator cache.
template<typename T>
class B{
T data;
};
voidOnStart (){
//B<int> b_int_0; // Compiler Error 'void' - unexpected token, probably type is missing?
B<void*> b; // OK
B<int> b_int_1; // OK
}
Bug MT5(build 2340) uses the same code twice: first pass - successful compilation, second pass - compilation error. Apparently the problems are related to the template function generator cache. The error disappears if for the template function "void run(const T &ff)" the transfer by reference is replaced by the transfer by value"void run(const T ff)".
Well, STL is not a one-size-fits-all solution. You have to pay much attention to specifics here.
You're confusing soft with warm.
It's not a question of STL. I'll figure it out there myself... (if someone doesn't have it, it doesn't mean that it can't be done in principle)
The easiest way to implement all the possible functionality with abstract methods in a base class or interface, and in the descendants - either implementation or =delte.
In this case, you need to pass pointers or references of the same type to the methods of the base class.
Although there is an unavoidable evil in the form of a virtual table, but it's better to arrange the architecture in such a way that there is no expensive branching via dynamic_cast anywhere.
The method you suggested was implemented earlier and also hinges on the same bug:https://www.mql5.com/ru/forum/1111/page2648#comment_15015191
The bug is in the priorities of calling reloaded functions when an implicit type conversion is performed for a pointer/class parameter.
In C++ all is OK, but in MQL the compilation error"ambiguous call to overloaded function"
One of the workaround variants is suggested above, but it is large and not convenient, and I have no desire to use it for a dozen of similar functions.
Perhaps there is something simpler?
Developers, please advise, are there any plans to fixthe bug or is this architecturally impossible?
Inside a template function, a passed pointer within an explicit type conversion behaves like a class, causing a compile-time error accordingly:
Dumb, can't solve a simple problem. I need to understand that trading is forbidden during the following EA startup settings.
This check does not work.
OrderCheck is a red herring. Please advise.
ANATOLI KAZHARSKI code
Thanks, didn't notice the MQL_TRADE_ALLOWED.
Dumb, can't solve a simple problem. I need to understand that trading is forbidden during the following EA startup settings.
This check does not work.
OrderCheck is a red herring. Please advise.
Probably the reason is the work of template class generator cache.
Bug MT5(build 2340) uses the same code twice: first pass - successful compilation, second pass - compilation error.
Apparently the problems are related to the template function generator cache.
The error disappears if for the template function "void run(const T &ff)" the transfer by reference is replaced by the transfer by value"void run(const T ff)".
Bug MT5(build 2340) Compilation error when attempting to access the internal class for a template parameter of a template function.