Bug (MQL5 compiler): Subclass inheriting from a parrent with the same parent classname in a parent namespace does not compile
namespace MainSpace { class CMyClass { public: CMyClass() { } }; namespace SubSpace { class CMyClass : public MainSpace::CMyClass { public: SubSpace::CMyClass(const long id); }; CMyClass::CMyClass(const long id) { } } }
Onno Rijkers #:
Hi Alain, thanks for your response.
I know I can use this workaround (as I mentioned in my original post). But this is just what I wanted to avoid as I now need to include the namespace in about 40 source code files. Hence my request for a (future) improvement.
Probably you want a template class (and need no namespaces):
template<typename T> class MyClass: public T { ... };
Then instantiate with MyClass<Main> or MyClass<Sub> (where Sub is derived from Main), as appropriate.
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
I have 2 classes with the same name but in different namespaces. When one of those classes (in the sub-namespace) inherits from the other (in the parent namespace), I get compiler errors.
This code should compile fine. It will, however, give me 9 errors. The first error is "'id' - unexpected token" (all other errors are related to that same constructor)
When removing the subclass' parent like:
Then it will compile fine.
==========================================================================================================
I can workaround by defining a different classname for the second class, but that defeats the purpose of inheritance within subnamespaces.
As such a construct is one of the strong properties of namespaces and OOP, I'd love to see this fixed.
The use case why this is such a strong construct:
CMyOtherClass will, by default inherit from MainSpace::CMyClass. But when I decide that CMyClass needs to be subclassed, I can simply create a SubSpace::CMyClass (that inherits from MainSpace::CMyClass) without changing any other code. CMyOtherClass will then automatically inherit from Subspace::CMyClass.
As I have a SubSpace in our current project with many small classes (about 40 - 50) that now inherit from MainSpace::CMyClass, I'll have the tedious task of editing all of them.