DeepThought:
Just a question - where could I find some specification about using const keyword syntax in MQL4 object declarations? I tried to search it, but nowhere it was mentioned. The documentation only describes using const in a function parameters list.
What do you want to know ?
Just a question - where could I find some specification about using const keyword syntax in MQL4 object declarations? I tried to search it, but nowhere it was mentioned. The documentation only describes using const in a function parameters list.
angevoyageur:
What do you want to know ?
I hoped Alex could reply with a link.
What do you want to know ?
DeepThought: Just a question - where could I find some specification about using const keyword syntax in MQL4 object declarations? I tried to search it, but nowhere it was mentioned. The documentation only describes using const in a function parameters list.
CData*const ConstPointer=GetPointer(DataPointer); // Constant pointer to CData.
- There isn't any except for: a const reference means you can only call const methods (type method(...) const{ ... },) and static members can be declared const
- There is nothing in the documentation about pointers to a const class.
In fact a const pointer can't be passed as a non-constant reference and a pointer to const class can't be passed at all: void OnStart() { const testConst* tc1= new testConst(); testConst* const tc2= new testConst(); test2(tc1); <<< 'tc1' - constant variable cannot be passed as reference test2(tc2); <<< 'tc2' - constant variable cannot be passed as reference } void test2(testConst& tc){
void OnStart() { const testConst* tc1= new testConst(); testConst* const tc2= new testConst(); test2(tc1); test2(tc2); <<< 'tc2' - constant variable cannot be passed as reference } void test2(const testConst& tc){
A constant pointer should be passable as a reference, and a pointer to a constant object should be passable as a constant reference. Build 625
alexvd:
We'll check it.
Thanks
Thanks :)
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
Hello All,
I am having some troubles working in MQL4 with object pointers. The above code is an example to demonstrate the dificulties that I am having. In this code I declare 3 pointers to a class "CData" the first is a "normal" pointer called DataPointer, the second is a pointer to a constant CData object and finally the third is a constant pointer to a CData object.
The normal pointer DataPointer allows writting to its elements as expected:
The pointer to a constant CData object doesn't allow as expected, and doing so causes a compilation error:
The constant pointer to a CData object allows writting to its elements as expected because only the pointer itself is constant:
Now the part that gets me confused is that the pointer to a constant CData object can not be made to point anywhere else as it should. The following line causes a compilation error :(
In any other object oriented programming language that I know this is allowed, is this a language bug? Or is it a feature of MQL4? I also searched the documentation and the forum to see if I am using that correct syntax and found nothing. Could anyone help me on this issue?
Thanks :)