Errors, bugs, questions - page 1873

 
Stanislav Korotky:
In the latest builds, have you corrected the bug that changing and recompiling EA code is not picked up by the tester? I have to close and reopen the terminal for the new version of ex5 to start testing. Otherwise, the old variant is tested.
I edit the Expert Advisor and either CTRL+F5, or directly in the Strategy Tester see the adequate result.
 
fxsaber:
I edit the Expert Advisor and either through CTRL+F5 or directly in the tester I see adequate results.
Ctrl+F5 is debugging, right? My problem is not with debugging, but with running a simple test.
 
Stanislav Korotky:
Ctrl+F5 is debugging, right? My problem is not with debugging, but with running a simple test.
Without visuals I run after edits - fine.
 
fxsaber:

How do I create a hidden class object with a closed constructor?

This is how the leaks are coming.

It's not clear how to call a destructor in this situation. Singleton is not it.

A class object with a closed constructor can only be created using a special static function of that class.

Although the compiler is not currently swearing at the code you cited, this will definitely be fixed in the future.

You can use a smart pointer to call the destructor.

The destructor must be open.

 
Koldun Zloy:

An object of a class with a closed constructor can only be created using a special static function of that class.

Although the compiler is not currently swearing at the code you cited, this will definitely be fixed in the future.

The proposed static method in this case will be some kind of self-deception, because it will be a constructor in essence. You will have to call it explicitly.

You can use a smart pointer to call the destructor.

The destructor must be open.

What is a smart pointer?
 

If you are sure that the constructor should be private, there is no other way.

A smart pointer is an object that contains a simple pointer and ensures that it is removed in time.

class MyClass
{
public:
   MyClass();
};

struct MyClassPtr
{
   MyClass* pMyClass;

   MyClassPtr( MyClass* myClass ) : pMyClass( myClass )
   {
   }
   ~MyClassPtr()
   {
      delete pMyClass;
   }
};

This is the simplest option.

There are also more complex smart pointers.

It's very well written about them in this book: https://rsdn.org/res/book/cpp/cpp_real_programmers.xml

C++ : библиотека программиста
  • rsdn.org
Глава 5. Умные указатели Глава 6. Ведущие указатели и дескрипторы Глава 7. Грани и другие мудрые указатели Глава 8. Коллекции, курсоры, итераторы Глава 9. Транзакции и гениальные указатели
 

what is missing to make the code compile:

class CMyClass
  {
public:
   void* core;
   CMyClass(void) : core(NULL) { }
   template<typename T>
   void Create(T* a_ptr) {
      core = dynamic_cast<T *> (a_ptr);
   }
  };

class CCore
  {
public:
   int var;
   CCore(void) : var(3) { }
  };


int OnInit() {
   CCore *_point_1 = new CCore();
   CMyClass _obj;
   _obj.Create(_point_1);
   int _val = _obj.core.var;
   
   delete _point_1;
//---
   return INIT_SUCCEEDED;
}

this variant writes 'var' - struct member undefined

PS. got the error ))

int _val = dynamic_cast <CCore *>(_obj.core).var;


 
void* from which build in the language?
 
fxsaber:
void* since which build in the language?

that's when the interfaces came in
 
Sergey Dzyublik:

when the interfaces came in.
Thank you. I did, however, immediately encounter an error
struct PTR
{
  void* Ptr; // internal error #40
};
Reason: