Errors, bugs, questions - page 1965

 
fxsaber:

Exactly! Now I can call f all sorts of functions and variables at once. There must be some common sense in such ambiguities, so as not to cause accidental errors. In my opinion, it's logical to bamboozle by issuing an empty string to typename f, rather than causing problems when you accidentally pick up and define another f.

Don't be so stubbornly searching for common sense everywhere, especially among bugs. If you listen to you, any bug in MQL is not a bug at all, but a feature that has been included by the wise developers ))

As already noted, if you have any doubts, the first thing to do is to check it in C++, and then come up with a solution.

As for ambiguities, they should cause a compiler error and no problems. Everything was clear and unambiguous in sample A100, so I don't quite understand what you mean. If you need to overload a function, you overload it and fix the compilation errors in ambiguities and that's it.

 

How do I initialise a static member of a template class in MQL?

template<typename T>
class xxx
{
  static int value;
};

template <typename T>
int xxx<T>::value = -1;
 
Stanislav Korotky:

How do I initialise a static member of a template class in MQL?

If it's a straightforward problem, bring it to a base non-template class and inherit it. In general, I don't know how.
 
Stanislav Korotky:

How do I initialise a static member of a template class in MQL?

template <typename T>
int xxx::value = -1;
 

A100:

template <typename T>
int xxx::value = -1;

In general, of course, this method does not correspond to C++, but it works in MQL.

I had a similar problem with method outside the class:

template<typename T>
class A
{
 public:
  void f();
};

template<typename T>
void A<T>::f() { }  //'A' - identifier already used

Thanks to you the solution has been found:

template<typename T>
void A::f() { }
Although this is also wrong of course, because it means defining a template method, not a method of a template class. And if a class contains both, there will be ambiguity
 
Alexey Navoykov:

I had a similar problem with taking a method outside the class:

This is much more convenient. The only restriction is that you can't have another class (like in the example) in between

Forum on trading, automated trading systems and strategy testing

Errors, Bugs, Questions

A100, 2016.05.19 23:26

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 );
}
Ошибки, баги, вопросы
Ошибки, баги, вопросы
  • 2016.05.19
  • www.mql5.com
Форум алго-трейдеров MQL5
 
Alexey Navoykov:

because it means defining a template method rather than a template class method. And if the class contains both, there will be ambiguity

There will be no ambiguity, everything has been thought out before us (c). We need to repeat the template line twice (the upper one will refer to a class, the lower one to a method)
 
A100:
It won't - it's all been thought out before us (c). You have to repeat the template line twice (the top one will refer to the class - the bottom one to the method)

Man, this looks really messed up.

A100:
It's much more convenient that way.

Yeah, well, not having to put <T> is just such a serious convenience.)

 
Alexey Navoykov:

Yeah, not having to put a <T> is such a serious convenience.)

I meant that it's convenient to be able to put a method outside a class
 
Alexey Navoykov:

I had a similar problem with taking a method outside the class:

wrong of course, as it means defining a template method rather than a template class method. And if the class contains both, there will be ambiguity.

I notice that methods are often placed outside the class, but why? I looked through the SB, so "small" methods are defined in one line at once, "long" methods are defined outside of the class. There is no perception convenience, because ALT+G in external definition offers not one, but two transition points. And if there are overloads, then a multiple of two, respectively. And ALT+M already shows everything at once.

Perhaps this is some kind of tribute to the clarity of the interface definition, but so far I haven't gotten into it.

Reason: