Errors, bugs, questions - page 1870

 
Slava:
And it shouldn't be possible.
But it used to be possible!
 
Tried to work it out
template <typename T>
class CLASS_COPY
{
public:
  T Data;

  CLASS_COPY( const T &Value )
  {
    Data = Value;
  }
};

template <typename T1, typename T2>
void Copy( T1 &ObjectDst, const T2 &ObjectSrc )
{
   const CLASS_COPY<T2> Object(ObjectSrc);
   const CLASS_COPY<T1>* ObjectCopy = dynamic_cast<const CLASS_COPY<T1>*>(&Object);
   
   ObjectDst = ObjectCopy.Data; // invalid pointer access
}

Compiles without problems, but crashes on execution with an error. How to write the Copy-function now?

 

DLLs that used to work don't work anymore. DLL's are 64 bit. Same dlls x32 on MT4 - work.

Windows 10 Home (x64 based PC), 1703, MT5 bild 1589
 
fxsaber:
I tried to wriggle out of it

It compiles without problems, but crashes on execution with an error. How to write a Copy-function now?

If dll is not critical, then memcpy. Or you may wait for the union.

Well, actually it is fun. The developers themselves called cast structures a standard alternative to unions and now they cannot cast them and haven't done it yet.

 
From which build to which EX5s are accepted in the Market?
 
Комбинатор:

In general, of course it's fun. Casting structures was called a standard alternative to union by the developers themselves, now you can't cast and associations aren't yet, right?

So with the advent of union it will be impossible to cast. Only simple cases will be possible.
 
fxsaber:

How to write Copy-function now?

As a complete perversion to use files, but natively
FileReadStruct - Файловые операции - Справочник MQL4
FileReadStruct - Файловые операции - Справочник MQL4
  • docs.mql4.com
FileReadStruct - Файловые операции - Справочник MQL4
 
Комбинатор:
How completely perverse to use files, but natively
Yeah, that's BOTH.
 

Forum on trading, automated trading systems and trading strategy testing

Bugs, bugs, questions

fxsaber, 2017.04.10 16:23

Creating unnecessary overloads which lead to compilation errors
template <typename T>
T Func()
{
  T Res;
  
  return(Res);
}

template <typename T>
void Func( T& Value )
{
  T Res = (MqlTick)Value;
}

void OnStart()
{
  Func<string>(); // без этой строки компилируется
  
  MqlTick Tick;
  
  Func(Tick);
}

The compiler is trying to create a

void Func( string& );
Why doesn't this code compile in 1589? There is no casting here.
 
Комбинатор:

If the dll is not critical, then memcpy. Or wait for union

In general, of course, it's funny. Casting structures was called by developers as a standard alternative to union, now it's impossible to cast and no unions yet, right?

just like that.