Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As several others have mentioned, the circular reference appears to be your problem. Another phrase for this would be "mutual dependency". However, rather than attempting to find the proper syntax to get your application to compile and run (I assume the actual problem exists in a program slightly more advanced than what you have posted), I would encourage you to attack the problem from an object-oriented design standpoint. </p> <p>As a general rule, mutual dependencies should be avoided wherever possible. I've come across this issue in my own code before (which resulted in several days of debugging, ripping my hair out, and cursing my compiler), and here is how I was finally able to overcome it. I will present a watered down version of my own problem as a concrete example of how to address the issue, so hopefully you can extract out the hidden meaning behind it all, and it will all make sense in the end.</p> <p>Let's say we have two classes: Data and DataAnalyzer</p> <p>Data holds a reference to DataAnalyzer (used to analyze the data), and DataAnalyzer holds a reference to Data (the data to be analyzed) -- mutual dependency! In order to eliminate this dependency, we extract out an interface (in C++, a pure virtual class) from DataAnalyzer that defines the public methods/attributes required on DataAnalyzer. It might look something like:</p> <pre><code>class IAnalyzer { public: virtual void Analyze () = 0; }; </code></pre> <p>When we define DataAnalyzer, we do it as follows:</p> <pre><code>class DataAnalyzer : public IAnalyzer { public: DataAnalyzer (Data* data); virtual void Analyze (); // defined in DataAnalyzer.cpp }; </code></pre> <p>And Data looks like:</p> <pre><code>class Data { public: Data (); IAnalyzer* Analyzer; }; </code></pre> <p>Somewhere, in your controller class, you might have something like:</p> <pre><code>void main () { Data* data = new Data (); data-&gt;Analyzer = new DataAnalyzer (data); } </code></pre> <p>Now, Data stands by itself (as far as it knows, IAnalyzer does not require a reference to Data), and only DataAnalyzer is dependent on Data. If you want to keep going, you could continue to remove DataAnalyzer's dependency on Data, but for the sake of simply breaking the mutual dependency, this should be sufficient.</p> <p><strong>Warning:</strong> I have not compile tested this code, so it may require some minor adjustment to compile and run properly.</p> <p>Good luck!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload