Download MetaTrader 5
To add comments, please log in or register
How to choose the most appropriate signal and subscribe to it in no time
GreenMoney
379
GreenMoney 2014.04.18 13:23 

Consider the following class definition:

class TestClass {
   struct SomeValues {
      int val_one;
      int val_two;
      double val_three;
   };
   public:
      SomeValues TestValues[5];
};

My goal was to create a private structure definition inside a class which would neither be accessible or creatable outside of the class. However, it seems that after I declare the above class, I'm able to then create a variable of the type "SomeValue" even though it exists as a private definition inside the class. For example:

int OnInit() {
   SomeValues JustTesting;
   JustTesting.val_one = 100;
   Print ("val_one of JustTesting is ", JustTesting.val_one);
   return(INIT_SUCCEEDED);
}

JustTesting #1

My thoughts on the above behavior are that the structure definition, in essence, creates a type definition which must exist at global scope.

Can I create a private structure definition in a class that is neither accessible or creatable from outside the class, and if so, any thoughts as to what I'm missing or doing wrong?

Ovo Cz
2955
Ovo Cz 2014.04.18 13:46  
Thirteen:

Consider the following class definition:

My goal was to create a private structure definition inside a class which would neither be accessible or creatable outside of the class. However, it seems that after I declare the above class, I'm able to then create a variable of the type "SomeValue" even though it exists as a private definition inside the class. For example:

My thoughts on the above behavior are that the structure definition, in essence, creates a type definition which must exist at global scope.

Can I create a private structure definition in a class that is neither accessible or creatable from outside the class, and if so, any thoughts as to what I'm missing or doing wrong?


From my experience, the class and structure definitions in MQL4 respect scope when declared inside methods, while they do not respect it at the base class level. I did not bother with it.
GreenMoney
379
GreenMoney 2014.04.19 19:59  

It appears that C++ (along with Visual Basic and Java, as well as other languages) allow one to completely encapsulate a private class or structure within a class so that the inner private class or structure is neither accessible nor creatable/declarable outside the scope of the outer class. See Nested Types (cppreference.com), class and struct nesting (stackoverflow.com), and in general paragraph 9.7 of ISO C++ Standard (pdf of 2012 working draft found here).

As an experiment, I used Visual Studio 2010 to create a C++ console project with the following additional code (VS C++ code below, not MQL):

#include "stdafx.h"

class Test_1 {
   struct tempStruct {
      int num3;
      double num4;
   };
   public:
      int num1;
      int num2;
      tempStruct num5;
};

int _tmain(int argc, _TCHAR* argv[]) {
   Test_1 test;
   test.num5.num3 = 5;
   //tempStruct tStruct; // including this line creates a compile-time error
   printf ("This is a test.  test.num5.num3 = %d", test.num5.num3);
   return 0;
}

The above code demonstrates that C++ allows me to completely encapsulate a private structure inside a class so that the structure is not accessible or creatable/declarable outside of the parent class. In particular, if I uncomment the line containing "tempStruct tStruct;", the compiler complains that tempStruct is undefined or an undeclared identifier. Contrast the behavior of the above C++ code to the behavior of the MQL code in my original post.

Ovo Cz
2955
Ovo Cz 2014.04.20 06:06  
Yes, even I am not a C++ coder, it is seems quite logical for the definition to respect its scope. The MQL4 is apparently following C++ syntax standards, so you definitively may ask for a fix. Though IMHO they still have a lot of work to be done in more critical areas.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.20 07:35  
Thirteen:

It appears that C++ (along with Visual Basic and Java, as well as other languages) allow one to completely encapsulate a private class or structure within a class so that the inner private class or structure is neither accessible nor creatable/declarable outside the scope of the outer class. See Nested Types (cppreference.com), class and struct nesting (stackoverflow.com), and in general paragraph 9.7 of ISO C++ Standard (pdf of 2012 working draft found here).

As an experiment, I used Visual Studio 2010 to create a C++ console project with the following additional code (VS C++ code below, not MQL):

The above code demonstrates that C++ allows me to completely encapsulate a private structure inside a class so that the structure is not accessible or creatable/declarable outside of the parent class. In particular, if I uncomment the line containing "tempStruct tStruct;", the compiler complains that tempStruct is undefined or an undeclared identifier. Contrast the behavior of the above C++ code to the behavior of the MQL code in my original post.


Have you tried reporting to Service Desk?
GreenMoney
379
GreenMoney 2014.04.21 20:23  
deysmacro:

Have you tried reporting to Service Desk?

I haven't reported it to the Service Desk yet. By posting in the forum, I was hoping someone would point out an error I made (and suggest a correction) or explain why MQL behaves differently than other languages regarding encapsulation of private structures/classes inside a class. If I don't receive any substantive replies within a few days regarding this issue, I will report it to the Service Desk.
GreenMoney
379
GreenMoney 2014.04.29 13:02  

An Update:

I submitted a report yesterday to the Service Desk about the issue in my original post. However, that report has been closed by the Support Team without any explanation. To date, I have not be given a reasonable explanation for why the current MQL4 compiler (b625) behaves the way I've demonstrated in my original post. Accordingly, until such a reasonable explanation is given for the behavior demonstrated in my original post, I consider such behavior from the current compiler (b625) to be a bug.

Image of submitted Service Desk report:

Image of Service Desk report

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.04.29 13:40  

Last time they also closed it when I report to them. You however, still can reply and show them how to reproduce the problem. Without any proper reproduce-able result, they will ignore you.

If you manage to catch their attention, they will open back.

GreenMoney
379
GreenMoney 2014.04.29 14:41  
deysmacro:

Last time they also closed it when I report to them. You however, still can reply and show them how to reproduce the problem. Without any proper reproduce-able result, they will ignore you.

If you manage to catch their attention, they will open back.

Not only did I link to this forum topic, but I gave them the code to reproduce the problem in the Service Desk report. See the image I included in my previous post. I don't believe there is any thing more that I could say or do to draw their attention to this matter.

If MetaQuotes chooses to ignore me, that is their prerogative. I'm only trying to help make their platform better.

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.04.29 15:34  
Thirteen:

Not only did I link to this forum topic, but I gave them the code to reproduce the problem in the Service Desk report. See the image I included in my previous post. I don't believe there is any thing more that I could say or do to draw their attention to this matter.

If MetaQuotes chooses to ignore me, that is their prerogative. I'm only trying to help make their platform better.

I asked some explanation.

ServiceDesk provided you an answer, but "the answer didn't appear on his side for some reason. We repeated".

ServideDesk

The compiler shouldn't allow the declaration/creation of a private structure/class outside of the enclosing class. Compare the above behavior to that C++.
Unfortunately, this behaviour won't be changed. Don't use such members if you prefer C++ style. Sorry.
GreenMoney
379
GreenMoney 2014.04.29 16:02  
angevoyageur:

I asked some explanation.

ServiceDesk provided you an answer, but "the answer didn't appear on his side for some reason. We repeated".

@angevoyageur

Thank you for your request for explanation. :) I can now see their additional reply on the Service Desk ticket.

/
To add comments, please log in or register