Errors, bugs, questions - page 2330

 
Ilyas:

I've roughly figured out the reason. I have a global variable.

CArrayObj actobjects;

Something with the initialization order of mcl environment and mission apparently, if actobjects a pointer and put an array there myself, nothing crashes. Class in global variables - bad practice, of course, I'll rewrite. But problems will arise with static arrays in functions (in µl the rule - initialization at first entry into function doesn't work).

In general, if it counts as a bug, then knowing approximately the cause, I can probably localize it.

 
pavlick_:

Anyway, if it counts as a bug, knowing roughly the cause, I can localise it I guess.

Nah, can't catch it, disappears miraculously after cutting out code. Even commenting out some lines (which don't execute before the crash) affects it.

 

There is a long code class, which lies in mqh. We need to create exactly the same class, which differs from the original one only in two lines (instead of less sign there should be more sign).

Can this be done without creating another almost identical mqh?


When the class is short, you can easily make it with a multi-line macro and everything comes out easy. But the code here is long.

I don't want to create an mqh-clone because if I fix one mqh, I will have to repeat all my actions in the second one. In addition, there is the human factor of forgetfulness and inattention.


You can still do it with a template class. But it is not at all obvious how it will affect the speed of execution. The class is needed for quick runs.

 
fxsaber:
#ifdef
 
TheXpert:
#ifdef

It won't work. Both classes must be in operation.

 
fxsaber:

It won't work. Both classes should be in operation.

I don't see a problem.

_____________

inheritance

putting differences into separate small classes

 
TheXpert:

I don't see a problem.

_____________

inheritance

Putting differences into separate small classes

There are several decent sized methods in a class. In each method you only need to replace the ">" sign with a "<" sign.

You can use a virtual like this
class A
{
private:
  virtual bool Compare()
  {
    return(true);
  }
public:

  bool f()
  {
    return(this.Compare());
  }
};

class B : public A
{
private:
  virtual bool Compare()
  {
    return(false);
  }
};


void OnStart()
{
  A a;
  B b;
  
  Print(a.f());
  Print(b.f());
}


But, unfortunately, we still need to pass the class initializing value. So I guess we'll have to use a template after all.

 
fxsaber:

I'd pass some adapters via template parameters (shouldn't be any brakes there), but if you want to be so clumsy, you can too. Make a hard link to the header file (mklink /H <link> <target>, if I'm not mistaken. You can google "windows create hard link"). And then enable this stuff in the usual way

#define _N C1    // имя класса
#define _M "c1"  // какой-то параметр
#include <qq.mqh>
#undef _N
#undef _M
#define _N C2
#define _M "c2"
#include <ee.mqh> // жёсткая ссылка на qq.mqh
#undef _N
#undef _M
 
pavlick_:

I'd pass some adapters via template parameters (shouldn't be any brakes there), but if you want to be so clumsy, you can too. Make a hard link to the header file (mklink /H <link> <target>, if I'm not mistaken. You can google "windows create hard link"). And then you just plug it in the usual way.

You're missing the point.

 
fxsaber:

You do not understand the question.

Well, I don't know, are you sure you understand me? Just in case the listing is qq.mqh and ee.mqh (one entity, changing one changes the other)

class _N
{
public:
   void f() {Alert(_M);}
};

All as ordered, class not inmacros, almost the same except _M.