template <typename T> class Foo;
Tho, still one error remains.
Have updated the main post.
I debugged further and learned that I need to forward declare generics like this
Tho, still one error remains.
Have updated the main post.
It's not clear why you need forward declaration at all with your simplified code.
#include<Generic\LinkedList.mqh> template<typename T> class Foo: public CLinkedList<T> { public: Foo(): CLinkedList<T>() { } public: void test() { Bar *bar = new Bar(GetPointer(this)); } };
#include<Test\Foo.mqh> #include<Test\FooNode.mqh> class Bar { public: Bar(Foo<FooNode*> *foo) { } };
#include<Test\Bar.mqh> Foo<FooNode*> *FOO; int OnInit() { return (INIT_SUCCEEDED); } void OnTick() { FOO = new Foo<FooNode*>(); }
I have developed a module based event listener framework to handle the complexity of the strategy. Until now I have not had to forward declare a generic variable.
This is simplified, to illustrate the problem, once the problem gets solved I will apply the solution on my framework. As the illustration is an identical structure to my code.
I have searched a solution in C++ related topics and what I have now is what I have found out, but still I'm stuck as I can't spot the mistake.
Although, I have plenty of experience in software development in other language, I have still hit a wall with this issue in C++ :).
I have developed a module based event listener framework to handle the complexity of the strategy. Until now I have not had to forward declare a generic variable.
This is simplified, to illustrate the problem, once the problem gets solved I will apply the solution on my framework. As the illustration is an identical structure to my code.
It's not identical as I solved it without forward declaration, as demonstrated in my previous post.
I went into this problem, too and maybe I found a solution or at least can tell where the problem is.
I guess the compilation fails when you try to compile the file where the forward-declared class is declared (Foo).
But this should be no problem, if you include the Foo-class with it's forward-declaration in another file and use it.
So it would only be an issue if you declare the forward-declaration in the EA-file itself because this is the only file you
have to compile.
Forward-declaration is completely legit because there are cases where the code gets much more complex if you work around it.
I hope this helps anyone.
And I found another, more "elegant" solution on stackoverflow:
Just include the file of the forward-declared class at the bottom of the file where the forward-declaration is. Now you can even compile the file Foo.
Still not perfect but I guess there is no better solution.
By the way, I just tested the test-code above and found no issue compiling it.
But my code is a bit different. I have a class A that includes class B and class B includes class C and class C works with methods from class A.
So I used forward-declaration to break the include-cycle.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I have used forward declaration before, but for some reason this situation fails. Any idea what I'm doing wrong?
I have attached the necessary files also.