Errors, bugs, questions - page 1588

 

You believe that

void f() const

can't change the pointer, but can change the object the pointer refers to. Well, there are no such pointers in MQL5 that can't be changed. Therefore, the const modifier always refers to the objects, to which the pointer refers.

 
Anton Zverev:

Then where do you think the constant pointer is here!

In methods f() and g() the a pointer becomes constant.

Well, there are no such pointers in MQL5 that can't be changed. Therefore, the const modifier always refers to the objects to which the pointer refers

You should not make such categorical conclusions without sufficient knowledge about the subject. MQL has constant pointers and declared them the same way as in C++.

 
Alexey Navoykov:

You should not make such categorical conclusions without sufficient knowledge of the subject. Constant pointers in MQL exist and are declared the same way as in C++.

How to declare a constant pointer in MQL5!
 

As far as I remember the developers' explanation, constancy applies to both object and pointer.

I.e. writing const T* in MQL === const T* const in C++

It was like that before, perhaps it is different now, but I doubt it.

 

Compilation error

template<typename T>
class A { public:
        bool operator==( const A& ); //error: 'operator' - function must have a body
        T t;
};
class B {
        A<int> a;
};
template<typename T>
bool A::operator==( const A& )  { return false; }
void OnStart()
{
        A<int> a, b;
        Print( a == b );
}
 

Compilation error

template<typename T>
class A { public: T t; };
class B { public:
template<typename T> void g(   T  * );
template<typename T> void f( A<T> * );
};
template<typename T> void B::g(   T  * ) {} //нормально
template<typename T> void B::f( A<T> * ) {} //ошибка: 'f' - member function already defined with different parameters
void OnStart()
{
        A<int> a;
        B b;
        b.g( &a );
        b.f( &a );
}
 
A100:

...

template<typename T>
bool A::operator==( const A& )  { return false; }

It should have been like this:

template<typename T>
bool A<T>::operator==( const A& )  { return false; }
 
Alexey Navoykov:

It should have been like this:

This would have been compatible with C++, on the other hand - only class B "interferes" there - if you remove it, it compiles without errors. This is the reason why it is aimed at checking
 

Compilation error

template<typename T>
class A {};
class B {
        void A() {}
        void f() { A(); } //error: 'A' - template mismatch
};
 

Compilation error

template<typename T> class A {};
template<typename T> class B {};
class C {
template<typename T>
        void f( B<A<T> > * ) {}
        B<A<int> > *b;
public:
        void g() { f( b ); } //error: 'f' - cannot to apply function template
};