You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Can you post actual codes to check?
I am using the OP's code, above, plus trivial tests of the class instantiation such as my messages a few minutes ago.
While there are ways of working round the problem, I agree with the OP that his code should compile successfully, but does not.
Can you post actual codes to check?
As for "default constructor" error, you should either define it in order to declare array of objects m_rows[], or change its type to array of pointers and create/copy instances as appropriate.
Sorry about the confusion, here are the updated codes with the forward declaration. I got compiler error:
Sorry about the confusion, here are the updated codes with the forward declaration. I got compiler error:
This was interesting so I reduced it down to a simple test case
'Foo<int>' - struct undefined (line 12)
'arrayFoo' - default constructor of class 'Foo<int>' is not defined (line 13)
Could you use a jagged object array to achieve your desired result?
Could you use a jagged object array to achieve your desired result?
Jagged Arrays
A variation of the multidimensional array is the jagged array: an array of arrays. A jagged array is a single-dimensional array, and each element is itself an array. The element arrays are not required to all be of the same size.
This is what I searched and found the definition of jagged array. In fact, I am implementing a jagged array. To make the code more readable, I removed all the other methods.
I got the following compilation errors:
'm_rows' - default constructor of class 'C1dArray<int>' is not defined mt Test forward declaration.mq4 29 15
object of 'C2dArray<int>' cannot be returned, copy constructor 'C2dArray<int>::C2dArray<int>(const C2dArray<int> &)' not found mt Test forward declaration.mq4 20 54
Anyway, I have reported this as a bug via the service desk and it has been accepted as open issue since 10 Oct.
Not sure if it helps but here is how you can create jagged arrays with the std lib classes.
And if you're just using std data types and you need a dynamic matrix then this should do the trick.
And if you're just using std data types and you need a dynamic matrix then this should do the trick.
Thanks, for your suggestion. I was fine using either way until I encountered the following requirement to pass a 2d array into 1darray as index:
This kind of indexing is very common in machine learning and python supports it natively. I am converting some python codes into MQL and trying to write nd arrays to support this kind of fanciful indexing which saves a lot of coding.
C2dArray stores C1dArray in m_rows. C1dArray operator[] needs to take in C2dArray as parameter. This requires a forward declaration for C2dArray before defining C1dArray. The sample code should compile but failed. I have changed to dynamic version per your suggestion:
Still the same error:
object of 'C2dArray<int>' cannot be returned, copy constructor 'C2dArray<int>::C2dArray<int>(const C2dArray<int> &)' not found mt Test forward declaration.mq4 24 56
object of 'C2dArray<int>' cannot be returned, copy constructor 'C2dArray<int>::C2dArray<int>(const C2dArray<int> &)' not found mt Test forward declaration.mq4 24 56