from where, to where, what and under what conditions was measured ?
just OrderSendAsync MODIFY and to the immediate next operation 5 sec ????
very strange, frightening, improbable result - we need to double-check the tests
I measured the time before and after the function, calculated the difference and got 5 seconds. In combat advisors everything is measured, so that there is more information to sort out an abnormal situation. Saw this.
Any function has its address in the .text segment.
Any member function (method), implicitly accepts this pointer as its first parameter.
Static methods do not accept the this pointer and are essentially syntactic "sugar", being, de facto, ordinary functions.
When a virtual function is called, the address of the executable function is taken from the virtual function table, the pointer to which is implicitly contained in the class in which the virtual function is declared. Initialisation of the pointer to the executable function occurs when creating an instance of the object, the logic is like this (I write it in mql on purpose so that it would be clear to all neophytes:
class Base;
class A;
class B;
void FooClassA(Base* p);
void FooClassC(Base* p);
typedefvoid(*_Foo)(Base*);
class Base{
public:
Base(): foo(NULL){}
void Foo() {foo(&this);}
protected:
_Foo foo;
};
class A: public Base{
public:
A():a(100){foo = FooClassA;}
int a;
};
class B: public A{
public:
B():b(-100){}
int b;
};
class C: public B{
public:
C(){foo = FooClassC;}
int Get() {return a+b;}
};
void FooClassA(Base* p){PrintFormat("%s: %i",__FUNCTION__,dynamic_cast<A*>(p).a);}
void FooClassC(Base* p){PrintFormat("%s: %i",__FUNCTION__,dynamic_cast<C*>(p).Get());}
voidOnStart(){
A a;
B b;
C c;
Base* p = &a;
p.Foo();
p=&b;
p.Foo();
p=&c;
p.Foo();
}
Naturally, in reality, everything is not like this, but the mechanism of initialisation of the pointer to the function is exactly like this. Accordingly, there is no way, from the word "at all", to do it the way you want in a compiled language.
C++ has such template magic:
#include <iostream>
#include <variant>
struct A
{
int a = 100;
int Get() { return a; }
};
struct B :A
{
int b = -100;
};
struct C :B
{
int Get() { return a + b; }
};
using BaseImpl = std::variant<A, B, C>;
struct Base : BaseImpl
{
using BaseImpl::BaseImpl;
int Get() { return std::visit([](auto&& arg) { return arg.Get(); }, static_cast<BaseImpl&>(*this)); }
};
int main()
{
Base a = A();
Base b = B();
Base c = C();
std::cout << a.Get() << ", " << b.Get() << ", " << c.Get() << std::endl; //100, 100, 0
b = C();
std::cout << a.Get() << ", " << b.Get() << ", " << c.Get() << std::endl; //100, 0, 0return0;
}
Any function has its address in the .text segment.
Any member function (method) implicitly accepts this pointer as its first parameter.
Static methods do not accept this pointer and are essentially syntactic "sugar", being de facto ordinary functions.
When a virtual function is called, the address of the executable function is taken from the virtual function table, the pointer to which is implicitly contained in the class in which the virtual function is declared. Initialisation of the pointer to the executable function occurs when creating an instance of the object, the logic is like this (I write it in mql to make it clear to all neophytes:
Naturally, in reality, it is not like this, but the mechanism of initialisation of the pointer to the function is exactly like this.
Thanks for the detailed explanation with an example!
If you are talking about my regret about the possibilities of interfaces. I want to impose only syntactic restrictions on classes/structures. That is, only at the compilation stage, as it happens with the same const modifier. For self-control, in short.
There is no way, from the word "at all", to do what you want in a compiled language.
I wrote a crutch above. I wanted to get something already built in for such cases.
Probably invented a bicycle, I don't know. If someone knows more elegant solutions, please share.
Previously (in old compiler builds) it was possible to use a class before its declaration:
class A;
class B
{
public: A a;
public: int Val;
};
class A
{
public: B * b;
public: int Test() {return b.Val + 1;}
};
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnStart()
{
B b;
b.a.b = GetPointer(b);
b.Val = 1;
Print(b.a.Test());
}
But now we get an error when compiling:
undefined class 'A' cannot be used
I came up with two solutions to get round this error.
1. Through the base class:
class A0
{
public: virtualint Test() {return0;}
};
class B
{
public: A0 * a;
public: int Val;
};
class A: public A0
{
public: A(B * source) {b = source;}
public: B * b;
public: virtualint Test() {return b.Val + 1;}
};
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnStart()
{
B b;
A a(GetPointer(b));
b.a = GetPointer(a);
b.Val = 1;
Print(b.a.Test());
}
2. Through a nested class:
class B
{
class A
{
public: B * b;
public: int Test() {return b.Val + 1;}
};
public: A a;
public: int Val;
};
//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnStart()
{
B b;
b.a.b = GetPointer(b);
b.Val = 1;
Print(b.a.Test());
}
The second solution, to my mind, is more optimal than the first one.
from where, to where, what and under what conditions was measured ?
just OrderSendAsync MODIFY and to the immediate next operation 5 sec ????
very strange, frightening, improbable result - we need to double-check the tests
I measured the time before and after the function, calculated the difference and got 5 seconds. In combat advisors everything is measured, so that there is more information to sort out an abnormal situation. Saw this.
It was necessary to create structures that could be given different rules of actions inside, but manipulated among themselves as identical.
The technique used was formalised on this example.
Unfortunately, I didn't understand why OOP languages don't have interfaces for static methods.
I have to create such a horror.
How do you imagine it?
Any function has its address in the .text segment.
Any member function (method), implicitly accepts this pointer as its first parameter.
Static methods do not accept the this pointer and are essentially syntactic "sugar", being, de facto, ordinary functions.
When a virtual function is called, the address of the executable function is taken from the virtual function table, the pointer to which is implicitly contained in the class in which the virtual function is declared. Initialisation of the pointer to the executable function occurs when creating an instance of the object, the logic is like this (I write it in mql on purpose so that it would be clear to all neophytes:
Naturally, in reality, everything is not like this, but the mechanism of initialisation of the pointer to the function is exactly like this. Accordingly, there is no way, from the word "at all", to do it the way you want in a compiled language.
C++ has such template magic:
Any function has its address in the .text segment.
Any member function (method) implicitly accepts this pointer as its first parameter.
Static methods do not accept this pointer and are essentially syntactic "sugar", being de facto ordinary functions.
When a virtual function is called, the address of the executable function is taken from the virtual function table, the pointer to which is implicitly contained in the class in which the virtual function is declared. Initialisation of the pointer to the executable function occurs when creating an instance of the object, the logic is like this (I write it in mql to make it clear to all neophytes:
Naturally, in reality, it is not like this, but the mechanism of initialisation of the pointer to the function is exactly like this.
Thanks for the detailed explanation with an example!
What's your idea of that?
If you are talking about my regret about the possibilities of interfaces. I want to impose only syntactic restrictions on classes/structures. That is, only at the compilation stage, as it happens with the same const modifier. For self-control, in short.
There is no way, from the word "at all", to do what you want in a compiled language.
I wrote a crutch above. I wanted to get something already built in for such cases.
Forum on trading, automated trading systems and testing trading strategies
New version of MetaTrader 5 build 3950: Withdrawal/Fill in the terminal and updated trading report
fxsaber, 2023.09.19 23:25
How to get rid of errors?The first time __LINE__/__COUNTER__ are passed inside the markos as text, the second time - numbers.
I came up with two solutions to get round this error.
1. Through the base class:
2. Through a nested class:
If it stops working, it would be good to know if it is correct.
If you make pointers instead of objects, the old version will work too.