Questions on OOP in MQL5 - page 18

 

Can you tell me how it differs ?
Creating an object, or pointer, in this way

class CClass
{
   public:


}CObj, *pCObj;

from the classic creature

CClass  CObj;
CClass *CObj;

Noticed different behaviour in the pros, started to wonder why, and literature search, don't even know what to call the first way to look.

 
Roman:

Can you tell me how it's different ?
Creating an object, or pointer, in this way

from the classic creature

I noticed different behaviour in the pluses, I wondered why, and the literature search, I don't even know what to call the first way to find it.

There is no difference, either in MQL or in pluses.

 
Koldun Zloy:

It's no different, whether in MQLs or pluses.

You do not understand the question. The difference is not in the languages, but in the declarations themselves.
I don't understand the behaviour of the object from the first example.
My guess is that the object is also created on the stack and destroyed afterthe class destructor is called, and the object is visible globally in the code.
That's what I wanted to clarify, what is the behaviour of the first method?
Am I guessing correctly?
What is it called to find it in google?

Because I've noticed (not in mql, but in C++) that if you create an object differently, then the behavior in the methods used changes, not as expected.

 
Roman:

You don't understand the question. The difference is not in the languages, but in the declarations themselves.
I don't understand the behavior of the object from the first example.
My guess is that the object is also created on the stack and is destroyed after calling the class destructor and the object is globally visible in the code.
That's what I wanted to clarify, what is the behaviour of the first method?
Am I guessing correctly?
What's it called so I can google it?

Because I noticed that if you create an object differently, the behaviour in the methods used changes, not as expected.

I understand the question. There is no difference in the advertisements.

 
Koldun Zloy:

I understand the question. There is no difference in the advertisements.

The difference is most likely in the scope.
The first example in one file is always globally visible, the second example or new, can be hidden in a function.

 
Roman:

The difference is most likely in the scope.
The first example in one file is always visible globally, the second example or new, can be hidden in a function.

The difference here is not how you declare it, but where.

 
Koldun Zloy:

It's not how you declare, it's where.

I, too, have come to that conclusion by logical reasoning :))
I wanted to be sure that my thoughts were correct. Thank you for the clarification.

 
Vladimir Simakov:
   lotDigits=MathMax(-(int)MathFloor(MathLog10(lotStep)),0);

I checked, this code does not work correctly to calculate the decimal point

Basically, mine doesn't always work correctly either, I know that.

a script to check it out:

void OnStart()
  {
   double l=0.0;
   for(int i=0; i<100; i++)
     {
      Print(l," ---> LotDigits / MyDigits = ",LotDigits(l)," / ",MyDigits(l));
      l+=0.003;
     }
  }
//+------------------------------------------------------------------+
int LotDigits(double value)
  {
   return(MathMax(-(int)MathFloor(MathLog10(value)),0));
  }
//+------------------------------------------------------------------+
int MyDigits(double v)
  {
   long i=10000000,k=long(v/0.0000001);
   int d=0;
   while(d<7 && k%i>0)
     {
      i/=10;
      d++;
     }
   return(d);
  }
//+------------------------------------------------------------------+

I have the script log attached.

Files:
20190829.log  9 kb
 
Roman:

Can you tell me how it differs ?
Creating an object, or pointer, in this way

from the classic creature

In the pros I noticed different behaviour, I wondered why, and the literature search, I don't even know what to call the first way to look.

Personally, I don't see much difference either, but the very style of such writing seems quite dangerous to me.

The pointer must be immediately, at creation, either equal to NULL or to the pointer to a real object. A small memory space is created where this pointer will be stored, either with a null value or as a normal pointer.

Declaring an object, on the other hand, creates the entire object, calling the constructor and allocating memory.

 
Igor Makanu:

I checked, this code does not work correctly in calculating the decimal point

Basically, mine doesn't always work correctly either, I know that.

a script to check it out:

I have the script log attached.

I have an assumption that there won't be a lot, like 0.15. At least I haven't heard of it. If I suddenly see one, I will redo it.