Errors, bugs, questions - page 2674

 

Please remind me if there is a neat way to resolve the "ambiguous call to overloaded function" error when you need separate handling for simple types and pointers, like this:

    template<typename V>
    void process(V value)
    {
    }

    void process(BaseFunctor *ptr)
    {
    }

Here the compiler considers that (BaseFunctor *) also corresponds to V. You can explicitly specify the type conversion when calling a method, but it's ugly. If you take a parameter by reference in a template function, you cannot pass constants and other temporary values (a variable is required).

 
Stanislav Korotky:
try adding an overload with a link
 
TheXpert:
try adding an overload with a reference

Do you mean overloading with object reference or pointer reference (which doesn't seem to exist)? I don't know how to slip a pointer to a distributed new instance into an object reference.

 
Artyom Trishkin:

Your cycle is not correct for closing positions. Make a reverse cycle.

Artyom Trishkin:

Your cycle is not correct for closing positions. Make a reverse cycle.

I'll try, but doesn't it matter how to loop if we are looking for all profitable positions of the same direction. We will go through all of them anyway and close the necessary ones.

 
Stanislav Korotky:

Do you mean overloading with object reference or pointer reference (which doesn't seem to exist)? I don't know how to slip a pointer to a distributed instance into an object reference.

With an object reference.

I have it like this:

class C {};

template<typename V>
void process(V value)
{
}

/* если добавить, компилируется
template<typename V>
void process(V& value)
{
}
*/

void process(C *ptr)
{
}
    
void OnStart()
  {
      C c;
      process(&c); // pointer, ok
      process(c); // 'process' - no one of the overloads can be applied to the function call       test2.mq5       32      7
  }
 
TheXpert:

with reference to objects.

I have it like this:

Still not that straightforward, sorry ;-). The class is used for inheritance:

class BaseFunctor
{
  public:
    virtual void process() = 0;
};

class MyFunctor: public BaseFunctor
{
  public:
    virtual void process() override
    {
    }
};

template<typename V>
void process(V value)
{
}

void process(BaseFunctor *ptr)
{
}

void process(BaseFunctor &ref)
{
}

void OnStart()
{
  process(new MyFunctor()); // 'process' - ambiguous call to overloaded function, could be one of 3 function(s)
}

If you could create a BaseFunctor, it would work, yes. But that's not the case.

 
Pavel Kozlov:

Hello!

Thank you for reporting the error!

Could you please elaborate on the problem with the picture?

No problem at the moment

 

The code below outputs 牖漠摲牥⁳湩潦〉〮र〲थ⸰〰㠉┰〉〮र

It's supposed to output the text test

The files are in the Files\\\Test\\ folder.

Function says that handle is correct it's 1 and immediately GetLastError says error 5008 Wrong handle ....

What should I do?

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   core();
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {

  }
//+------------------------------------------------------------------+
void core()
  {
   string value = "", name = "";

   name =  "Test" + "\\test.csv";
   Print(FileIsExist(name));

   ResetLastError();

   int m_hendle = -1;
   m_hendle = FileOpen(name, FILE_READ | FILE_WRITE | FILE_CSV);
   if(m_hendle != INVALID_HANDLE)
     {
      Print((string)m_hendle + "    " + name + " [" + (string)FileSize(m_hendle) + "]"+ (string)GetLastError());
       while(!FileIsEnding(m_hendle))
        {
         string sCurrent = FileReadString(m_hendle);
         Print("sCurrent = ", sCurrent);
        }
      FileClose(m_hendle);
     }
  }
//+------------------------------------------------------------------+
 
Sergey Dzyublik:
Very nasty MT5(build 2316) bug, blocking further development.
You create a complex wrapped object with internal type "C" several times, but it turns out to be quite a different data type, maybe "B", "int", whatever you want...

It took me a lot of time and effort to find and understand that the problem is not in the code but in the MQL compiler. (C++ online:https://onlinegdb.com/H1R1fR5ML)
Presumably, the problem is in the work of the template class "main_wrapper" cache during code generation at compilation time when the internal class "internal_wrapper" from the template class "A" is passed as a parameter for different data types (int, B*, B, C).
What first data type is created by the template class "main_wrapper<A<TEMPLATE_TYPE>::internal_wrapper>, such data type will be further used in all objects of the template in the future.


Another bug with the generation of the template class code will be provided below.

Thanks for the post, fixed

 
Vladimir Pastushak:

The code below outputs 牖漠摲牥⁳湩潦〉〮र〲थ⸰〰㠉┰〉〮र

It's supposed to output the text test

The files are in the Files\\\Test\\ folder.

Function says handle is correct it's 1 and immediately GetLastError says error 5008 Wrong handle ....

What should I do?

What encoding is the file in?

Reason: